Hobolord
Board Regular
- Joined
- Sep 9, 2015
- Messages
- 64
Hello,
I am using Excel 2013, Windows 7, on a PC.
I am attempting to have my code import a text file to excel. This should be very simple. I used the recorder, but the code is bugging on the
line, and if I remove that, it doesn't import any data either.
My code matches all code I'm able to find via Google. Someone please help
.
Code:
I am using Excel 2013, Windows 7, on a PC.
I am attempting to have my code import a text file to excel. This should be very simple. I used the recorder, but the code is bugging on the
Code:
.Commandtype = 0
My code matches all code I'm able to find via Google. Someone please help

Code:
Code:
Dim filepath As String
filepath = InputBox("Please enter the filepath for the audit report .txt file" & vbNewLine & vbNewLine & "For example: 'C:\Users\cbs1715\Desktop\Audit Report 09282016.txt'", "Enter Filepath")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & filepath, Destination:=Range _
("$A$1"))
.Commandtype = 0
.name = "Audit Report"
.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 = True
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(17, 13, 17, 16, 27, 5, 4)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With