gbrendemuehl
MIS
I am getting an error implementing the solution presented in the previous thread titled "Running Excel Web Query & Importing to Access". The error is "Error 9 - Subscript out of range" on the statement "Set objQueryTable = objWorkSheet.QueryTables(strQueryTable)"
Here is my code:
I have checked the filename, sheet and query names and they look correct. I'd appreciate you help.
Thanks
Gary
Here is my code:
Code:
Private Sub cmdTrack_Click()
Status = UpdateExcelQueryTable("c:\Documents and Settings\Administrator\My Documents\The Orchid Grove\qryUSPS.xls", "Sheet1", "USPSTracking")
Public Function UpdateExcelQueryTable(strWorkbook As String, strSheet As String, strQueryTable As String) As Boolean
On Error GoTo Err_Handler
'
Dim appExcel As Object
Dim objWorkSheet As Object
Dim objQueryTable As Object
'
Set appExcel = GetObject(strWorkbook)
Set objWorkSheet = appExcel.Worksheets(strSheet)
objWorkSheet.Visible = True
Set objQueryTable = objWorkSheet.QueryTables(strQueryTable)
objQueryTable.Refresh False
While objQueryTable.Refreshing
'Do Nothing
Wend
Set objQueryTable = Nothing
Set objWorkSheet = Nothing
appExcel.Close True
Set appExcel = Nothing
UpdateExcelQueryTable = True
Exit_Handler:
Exit Function
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, vbExclamation, "UpdateExcelQueryTable()"
UpdateExcelQueryTable = False
Resume Exit_Handler
End Function
I have checked the filename, sheet and query names and they look correct. I'd appreciate you help.
Thanks
Gary