View Full Version : How To Bypass A Webquery Error Message
mrprofit
04-15-2014, 11:23 PM
I get error message sometime when webquery fail to fetch the data, how do i bypass this error message and continue to the next task
mrprofit
04-15-2014, 11:31 PM
the code,
Sub WEEKLY_Update()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Workbooks.Open Filename:= _
Sheets("Sheet1").Range("R3").Value & Sheets("Sheet1").Range("S3").Value
Application.Run "'" & ActiveWorkbook.Name & "'!GetQuery"
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Sheet2").Select
Application.Run "'" & ActiveWorkbook.Name & "'!CutCopySelectAll"
ActiveWorkbook.Save
ActiveWorkbook.Close
Workbooks.Open Filename:= _
Sheets("Sheet1").Range("R3").Value & Sheets("Sheet1").Range("S4").Value
Application.Run "'" & ActiveWorkbook.Name & "'!GetQuery"
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Sheet2").Select
Application.Run "'" & ActiveWorkbook.Name & "'!CutCopySelectAll"
ActiveWorkbook.Save
ActiveWorkbook.Close
.....................
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Excel Fox
04-17-2014, 07:58 AM
Try this
Sub WEEKLY_Update()
Application.ScreenUpdating = False
Workbooks.Open Filename:=Sheets("Sheet1").Range("R3").Value & Sheets("Sheet1").Range("S3").Value
Call QueryError("'" & ActiveWorkbook.Name & "'!GetQuery")
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Sheet2").Select
If Not QueryError("'" & ActiveWorkbook.Name & "'!CutCopySelectAll") Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else
ActiveWorkbook.Close False
End If
Workbooks.Open Filename:=Sheets("Sheet1").Range("R3").Value & Sheets("Sheet1").Range("S4").Value
Call QueryError("'" & ActiveWorkbook.Name & "'!GetQuery")
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Sheet2").Select
If Not QueryError("'" & ActiveWorkbook.Name & "'!CutCopySelectAll") Then
ActiveWorkbook.Save
ActiveWorkbook.Close
Else
ActiveWorkbook.Close False
End If
Application.ScreenUpdating = True
End Sub
Function QueryError(strQueryToRun As String) As Boolean
On Error Resume Next
Application.Run strQueryToRun "'" & ActiveWorkbook.Name & "'!GetQuery"
If Err.Number Then
Err.Clear: On Error GoTo 0: On Error GoTo -1
QueryError = True
End If
End Function
mrprofit
04-17-2014, 12:32 PM
Application.Run strQueryToRun '"'" & ActiveWorkbook.Name & "'!GetQuery"
is there a ' in this line? it shows an error on this line
Excel Fox
04-17-2014, 06:39 PM
Sorry about that, yes that ' needs to be removed. It wasn't supposed to be there. Correcting it now.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.