Hi Guys,
I am using this function to import CVS into workbook:
And after import i want to create listobject from imported data, i am doing:
and getting error:
so it means that this code is not working:
Why this is not working? Can anybody explain?
Crossposted from here:
Importing CSV into workbook and creating listobject
Jacek
I am using this function to import CVS into workbook:
VBA Code:
Function ImportDataCSVQuery(wsh, workbookToImportPath, ThisWb)
With wsh
' Downloads .csv file with header row
With .QueryTables.Add(Connection:="TEXT;" & workbookToImportPath, Destination:=wsh.Range("A1"))
.Name = "Connection"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.TextFileDecimalSeparator = "."
.TextFileThousandsSeparator = ","
.Refresh BackgroundQuery:=False
End With
End With
ThisWb.Connections(ThisWb.Connections.Count).delete
End Function
And after import i want to create listobject from imported data, i am doing:
VBA Code:
With wshTemp
lstrow = .Cells(ActiveSheet.Rows.Count, "A").End(xlUp).row
lstcolumn = .Cells(1, ActiveSheet.Columns.Count).End(xlToLeft).Column
.ListObjects.Add(xlSrcRange, .Range(.Cells(1, 1), .Cells(lstrow, lstcolumn)), , xlYes).Name = "TEST"
End With
and getting error:
so it means that this code is not working:
VBA Code:
ThisWb.Connections(ThisWb.Connections.Count).delete
Why this is not working? Can anybody explain?
Crossposted from here:
Importing CSV into workbook and creating listobject
Jacek