VB isn't my area... I'm having trouble trying to get the QueryTable to actually populate the data into the active worksheet in Excel. It works in that it prompts me to navigate and select my data source file. The problem is once I select the data file source I get a "Run-Time error 1004" with the message that MS Excel cannot access the file "insert file path here" that I had just selected. What am I missing?
Here's the code:
Sub ImportAutoRead()
Dim fopen As Variant
fopen = Application.GetOpenFilename("Auto Read Files (*.imp), *.imp")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fopen _
, Destination:=Range("$A$2"))
.Name = fopen
.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(9, 2, 2, 2, 9)
.TextFileFixedColumnWidths = Array(106, 12, 4, 6)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Here's the code:
Sub ImportAutoRead()
Dim fopen As Variant
fopen = Application.GetOpenFilename("Auto Read Files (*.imp), *.imp")
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fopen _
, Destination:=Range("$A$2"))
.Name = fopen
.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(9, 2, 2, 2, 9)
.TextFileFixedColumnWidths = Array(106, 12, 4, 6)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub