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
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
the code,
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
Last edited by mrprofit; 04-15-2014 at 11:37 PM.
Try this
Code: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
Last edited by Excel Fox; 04-17-2014 at 06:40 PM. Reason: Removed '
A dream is not something you see when you are asleep, but something you strive for when you are awake.
It's usually a bad idea to say that something can't be done.
The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve
Join us at Facebook
Application.Run strQueryToRun '"'" & ActiveWorkbook.Name & "'!GetQuery"
is there a ' in this line? it shows an error on this line
Sorry about that, yes that ' needs to be removed. It wasn't supposed to be there. Correcting it now.
A dream is not something you see when you are asleep, but something you strive for when you are awake.
It's usually a bad idea to say that something can't be done.
The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve
Join us at Facebook
Bookmarks