I'm stuck trying to make this more automated:
Right now, it will open a dialog box to the default directory. After selecting the file, the macro completes.
I would like to hardcode the directory (c:\users\whatever) and have it automatically import the newest file. Is this possible?
I've read similar posts through the forum but don't know enough to modify my code myself. Big thanks in advance!
Code:
Sub Import()
Workbooks.Add
Filename = Application.GetOpenFilename("TXT Files (*.txt), *.txt")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & Filename, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Cells.Select
Selection.ColumnWidth = 8
Range("K1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$N$189").AutoFilter Field:=8, Criteria1:="TRUE"
ActiveSheet.Range("$A$1:$N$189").AutoFilter Field:=4, Criteria1:="=32767", _
Operator:=xlAnd
End Sub
Right now, it will open a dialog box to the default directory. After selecting the file, the macro completes.
I would like to hardcode the directory (c:\users\whatever) and have it automatically import the newest file. Is this possible?
I've read similar posts through the forum but don't know enough to modify my code myself. Big thanks in advance!