Hi,
I am attempting to import a text file, but I get an error "(10094) ActiveX Automation: Object var is 'Nothing'."
Not sure what the mistake here is.
I am attempting to import a text file, but I get an error "(10094) ActiveX Automation: Object var is 'Nothing'."
Not sure what the mistake here is.
Code:
Sub vba_excel_importing_file()
Dim strFileName As String
strFileName = InputBox("Enter the full path to the comma " & _
"separated file to import")
Set oExcel = CreateObject("Excel.Application")
With oExcel.ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strFileName, Destination:=oExcel.Range("A1") _
)
oExcel.Name = "vba excel importing file"
oExcel.FieldNames = True
oExcel.RowNumbers = False
oExcel.FillAdjacentFormulas = False
oExcel.PreserveFormatting = True
oExcel.RefreshOnFileOpen = False
oExcel.RefreshStyle = xlInsertDeleteCells
oExcel.SavePassword = False
oExcel.SaveData = True
oExcel.AdjustColumnWidth = True
oExcel.RefreshPeriod = 0
oExcel.TextFilePromptOnRefresh = False
oExcel.TextFilePlatform = 437
oExcel.TextFileStartRow = 1
oExcel.TextFileParseType = xlDelimited
oExcel.TextFileTextQualifier = xlTextQualifierDoubleQuote
oExcel.TextFileConsecutiveDelimiter = False
oExcel.TextFileTabDelimiter = False
oExcel.TextFileSemicolonDelimiter = False
oExcel.TextFileCommaDelimiter = True
oExcel.TextFileSpaceDelimiter = False
oExcel.TextFileColumnDataTypes = Array(1, 1, 1, 1)
oExcel.TextFileTrailingMinusNumbers = True
oExcel.Refresh BackgroundQuery:=False
End With
End Sub
Comment