Results 1 to 5 of 5

Thread: How To Bypass A Webquery Error Message

  1. #1
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0

    How To Bypass A Webquery Error Message

    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

  2. #2
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    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.

  3. #3
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    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

  4. #4
    Member
    Join Date
    Apr 2014
    Posts
    45
    Rep Power
    0
    Application.Run strQueryToRun '"'" & ActiveWorkbook.Name & "'!GetQuery"

    is there a ' in this line? it shows an error on this line

  5. #5
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    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

Similar Threads

  1. Difference Between 'On Error GoTo 0' And 'On Error GoTo -1'
    By Transformer in forum Familiar with Commands and Formulas
    Replies: 7
    Last Post: 07-02-2015, 04:07 PM
  2. Message To Cross Posters
    By Excel Fox in forum Public News
    Replies: 1
    Last Post: 11-09-2013, 02:07 AM
  3. Code to pop up message when there is a variance
    By Howardc in forum Excel Help
    Replies: 1
    Last Post: 08-13-2013, 12:45 PM
  4. VBA Confirm Message Before Deleting Row
    By mackypogi in forum Excel Help
    Replies: 14
    Last Post: 08-12-2013, 11:23 AM
  5. Message Box Before Saving Document
    By Lucero in forum Excel Help
    Replies: 2
    Last Post: 04-15-2012, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •