Following is the macro code for my application to get the data from a CSV file to an Excel file. It is located in the same location. But I am unable to import the data.
It is giving an error:
Runtime Error 1004 Method 'Range of object' _Global' failed.
Excel VBA based application code:
Sub LoadFromFile()
Dim fileName As String
Dim folder As String
Dim lastRow As Long
Dim dest As String
If IsEmpty(Range("A1").Value) = True Then
lastRow = 1
Else: If IsEmpty(Range("A1").Value) = False Then GoTo Line1x
Line1x:
With ActiveSheet
lastRow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
End With
End If
ActiveSheet.UsedRange.Clear
dest = "$A$" & lastRow
folder = "C:\xampp\htdocs\sites\repairrequest\database.csv"
With ActiveSheet.QueryTables _
.Add(Connection:="TEXT;" & folder, Destination:=Range("dest"))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
Range(dest)
asdest
is a string variable not a named range. – SJR