Here's how to choose the file and create the QueryTable:
Sub Import_FMR_Data2()
Dim strName As String
Dim strTName As String
strName = Application.GetOpenFilename("Text Files (*.txt),*.txt")
strTName = Replace(Split(strName, "\")(UBound(Split(strName, "\"))), ".txt", "")
On Error Resume Next
Cells.QueryTable.Delete
On Error GoTo 0
Cells.ClearContents
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strName _
, Destination:=Range("$A$1"))
.Name = strTName
.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 = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(50, 20, 20, 20)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Bookmarks