error handling

SQUIDD

Well-known Member
Joined
Jan 2, 2009
Messages
2,104
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi all

I have several macro's that i believe i have handled all the errors.

But i was wondering.

Is there a way, above all the macros to have a general error handler.

something that oversees all the modules.

As whatever error may occur other than the ones i have thought of.

i would like to run a very simple process.

not essential but just wondering.

Dave
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Re: error handeling

Logically, the error occurs within the active procedure, so that is where the handler would be triggered. But it is conceivable that a public procedure could be called to handle the error. It would require passing the error number, at a minimum, to the handler so that it could display a message to the user of what the problem is. I can visualize an algorithm of various error numbers to remedies that might be initiated at the user's option. But something of that nature would be a coding project in itself. It would be even more complex to try and handle user created errors that are not in the standard application menu of trappable errors.
 
Last edited:
Upvote 0
Re: error handeling

Hi JLGWhiz

Yep, that sounds far too complicated for such a small probelm.

I think i will live with it.

The actual problem may not even be an error, more a notification.

I use IE to download data from the web and it would appear that when it hangs.

This pops up.

MICROSOFT EXCEL IS WAITING FOR ANOTHER APLICATION TO COMPLETE AN OLE ACTION.

At this point i have to break out the code and start from the last save point, its no real hassel, just annoying.
So if there was a way to automate that part would be great.

I posted the above on the off chance it may be a simple fix

Thanks anyway, i can live with it.

Dave
 
Upvote 0
Re: error handeling

I am not a web scraping expert, in fact, I have never even attempted download anything that was not on a forum or had a download button to click. So, any advice I would give would probably be worthless with reagard to the delay alert you are getting. But if you had put that in the title of your post and explained the problem as you have here, somebody could probably have helped you with it. It pays to use a good thread title that pin points your problem when posting. Maybe if you start a new thread using that title you can get some expert help from someone who does write code for web queries. I know I have seen similar posts before.

Here is one possible solution in this link
https://answers.microsoft.com/en-us...lication/a2dcb2a7-8e49-4db5-96de-eb29010f2f67


Regards, JLG
 
Last edited:
Upvote 0
Re: error handeling

It sounds as if you are going asynchronously and running into a timing problem. Do you have the following code?
XMLpage.Open "GET", URL, True
or is there no second argument, in which case you are running asynchronously; add ",False" or change it to "True" to see what happens.

Unless you are doing really massive web scraping, my recommendation is to stay with False, aka synchronous, or doing things in a time-wise linear fashion.
 
Upvote 0
Re: error handeling

Hi JLG whiz, thanks for that, i will try the suggestion many thanks, although i fear it may still hang and simple not notify me.

wornhall.

thanks for the suggestion, i will post my code below in case you spot anything obvious.

Code:
Sub DOWNLOAD_6_greyhounds()

Sheets("APP").Activate
Application.ScreenUpdating = False
DoEvents

''''''''''''''''''''''''''''''''''''''''CLEAR 12 PAGES OF DATA''''''''''''''''''''''''''''''''''''''''
    For d1 = 1 To 6
        With Sheets("TRAP" & d1)
            .Range("A2:M200").ClearContents
        End With
        With Sheets("T" & d1 & "_DL")
            .Columns("A:M").AutoFilter
             .Range("A:A").ClearContents
        End With
    Next d1

''''''''''''''''''''''''''''''LOAD ALL 6 WEB PAGES AND CLICK 100 ROWS, ALSO GET NUMBER OF PAGES''''''''''''''''''''''''''''''''''''''''
Dim ie(6) As Object
Dim Doc(6) As Object
For i = 1 To 6
         Set ie(i) = CreateObject("InternetExplorer.Application")
         With ie(i)
            .Visible = True
            .Height = 200
            .Width = 200
            .Left = 900
            .Top = 80
            .Navigate "http://www.gbgb.org.uk/RaceCard.aspx?dogName=" & Range("'dogs'!$B$" & i + 1).Value
             Do While ie(i).Busy: DoEvents: Loop
             Do While ie(i).readyState <> 4: Loop
         End With



    Set Doc(i) = ie(i).document
               On Error Resume Next
            Doc(i).getElementById("ctl00_ctl00_mainContent_cmscontent_DogRaceCard_lvDogRaceCard_ctl00_ctl03_ctl01_PageSizeComboBox_Input").Focus
            Application.SendKeys "100{RETURN}"
            Do While ie(i).Busy: DoEvents: Loop
            Do While ie(i).readyState <> 4: Loop
            
    
        On Error Resume Next
        If IsError(Doc(i).getElementsByClassName("rgWrap rgInfoPart")(0).getElementsByTagName("strong")(0).innerText) Then
            nofpages = 1
        Else
            nofpages = Application.Ceiling(CLng(Doc(i).getElementsByClassName("rgWrap rgInfoPart")(0).getElementsByTagName("strong")(0).innerText) / 100, 1)
        End If
    
    Range("'APP'!$F$" & i + 9) = nofpages
    Range("'APP'!$d$" & i + 9) = "web page loaded, downloading"
    Application.ScreenUpdating = True
    DoEvents
    Application.ScreenUpdating = False

Next i

''''''''''''''''''''''''''''COPY DATA FROM WEB PAGES, PASTE THE DATA AND CLICK PAGE 2 ON INTERNET IF NEEDED''''''''''''''''''''''''''''
For y = 1 To 6
    ie(y).ExecWB 17, 0
    ie(y).ExecWB 12, 2
        Sheets("T" & y & "_DL").Select
        Range("a1").Select
        ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
        Application.CutCopyMode = False
            If Range("'APP'!$F$" & y + 9) > 1 Then
                Set Doc(y) = ie(y).document
                Doc(y).getElementsByClassName("rgPageNext")(0).Click
            Else
                ie(y).Quit
            End If
            Range("'APP'!$d$" & y + 9) = "complete"
Next y
Call filter_and_copy 'FILTER THE DATA AND CLEAR IN OTHER SHEETS AND PASTE ON NEW SHEET''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''TURN OFF AUTO FILTER AND CLEAR DATA'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    For dd = 1 To 6
        With Sheets("T" & dd & "_DL")
            .Columns("A:M").AutoFilter
             .Range("A:A").ClearContents
        End With
    Next dd
    
'''''''''''''''''''''''''''''''''''COPY PAGE 2'S IF THEY EXIST AND PASTE DATA''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For q = 1 To 6
    If Range("'APP'!$F$" & q + 9) > 1 Then
        ie(q).ExecWB 17, 0
        ie(q).ExecWB 12, 2
        Sheets("T" & q & "_DL").Select
        Range("a1").Select
        ActiveSheet.PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False
        Application.CutCopyMode = False
        ie(q).Quit
    Else
    End If
Next q
Call filter_and_copy 'FILTER THE DATA AND CLEAR IN OTHER SHEETS AND PASTE ON NEW SHEET''''''''''''''''''''''''''''''''''''''''''''''''
Sheets("APP").Activate
Application.Run "CHART_DATA"
End Sub
Sub filter_and_copy()
Dim sht As Worksheet
Dim LastRow As Long
    For sh = 1 To 6
        With Sheets("t" & sh & "_DL")
            .Columns("A:M").AutoFilter
            .Range("$A$1:$M$2000").AutoFilter Field:=13, Criteria1:="<>*error*", Operator:=xlAnd
            .AutoFilter.Range.Offset(1, 2).Copy
        End With 'add date wron into formula to filter out'and check the track matches in the formula
        Set sht = ThisWorkbook.Worksheets("TRAP" & sh)
         LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1
        With Sheets("TRAP" & sh)
            .Range("A" & LastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End With
    Next sh
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top