justgotloud
New Member
- Joined
- Nov 2, 2020
- Messages
- 2
- Office Version
- 365
- 2019
- Platform
- Windows
Everything was sort of working great when automatically importing a csv file to excel...except that it was putting all data into column A. So I added the line .TextFileCommaDelimiter = True to my vba macro, re-ran and now I get the error 'application -defined or object -defined error' When I click debug, it takes me to the newly added line.
Any ideas what I am doing wrong?
VBA Code:
Sub csvimp()
Dim lngConn As Long
url1 = Sheets("urls").Range("B2")
Sheets("csvimp").Cells.ClearContents
Sheets("csvimp").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;" & url1 _
, Destination:=Range("A1"))
.Name = _
"data"
.FieldNames = True
.RowNumbers = False
.TextFileCommaDelimiter = True
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
With ThisWorkbook
For lngConn = .Connections.Count To 1 Step -1
.Connections(lngConn).Delete
Next lngConn
End With
End Sub
Any ideas what I am doing wrong?