hey guys,
I have code in MS Access that opens an XL object and runs vba code that was recorded with the macro recorder by way of a test simulation in excel. the night is a bit long and I'm missing something very simple. Here is the part of my code that is erroring out:
Function get_traffic_data()
Dim xl As Excel.Application
Set xl = New Excel.Application
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim query_counter As Long
Dim query_next As Long
query_counter = DLookup("counter", "tbl_qry_ctr")
query_next = query_counter + 1
Set wb = xl.Workbooks.Open("C:\Users\Owner\Desktop\site_traffic.xlsm")
wb.Queries.Add Name:="Table 0 (" & CStr(query_next) & ")", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://www.site.com/f/f.php""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & _
Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""VISITOR IP ADDRESS, ISP NAME"", type text}, {""VISITOR DOMAIN ADDRESS"", _
type text}, {""PAGE VISITED"", type text}, {""DATE"", type date}, {""TIME"", type time}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Worksheets.Add
With wb.ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0 (2)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
the code is throwing error Method Range of Object_Global Failed at this line:
With wb.ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0 (2)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
can you guys help me spot the error? I know it's very simple. There IS a table named Table 0 (2) so I think the issue is with the code Range($A$1). Sometimes I think a bit too much. thanks.
Bookmarks