Internetexplorer.application Error Handling
Contents |
which you want to receive events "functionprefix" The prefix of the functions you define to handle receiving events. The prefix is appended by the Objects method name. "interface name" [optional] autoit catch error name of an Event interface to use. Note: It must be a autoit error handling example supported as outgoing for the Object AND it must be of type DISPATCH. Return Value Success: an object or autoit on error resume next a function name. Failure: sets the @error flag to non-zero. Remarks The first format is used to receive Events from the given Object. To receive a specific event, create an
Createobject( Internetexplorer.application ) Vba
AutoIt function name using the given prefix appended with the event name. The second format is used for COM Error Handling. If any COM error occurs, the given function is being called. First parameter for the function will be error object. You can use it to access different properties of this object. If the second parameter is omitted, it will return the autoit @error name of the current Error handler function or function, depending what was used when registering. Properties of the AutoIt Error Object: .number The Windows HRESULT value from a COM call .windescription The FormatWinError() text derived from .number .source Name of the Object generating the error (contents from ExcepInfo.source) .description Source Object's description of the error (contents from ExcepInfo.description) .helpfile Source Object's helpfile for the error (contents from ExcepInfo.helpfile) .helpcontext Source Object's helpfile context id number (contents from ExcepInfo.helpcontext) .lastdllerror The number returned from GetLastError() .scriptline The script line on which the error was generated See the Obj/COM Reference for a detailed explanation. Related GUICtrlCreateObj, IsObj, ObjCreate, ObjGet Example Example 1 #include
be down. Please try the request again. Your cache administrator is webmaster. Generated Wed, 19 Oct 2016 03:23:51 GMT by s_wx1196 (squid/3.5.20)
Ever wanted to automate logging into a website. Well you can automate Internet Explorer to perform such tasks quite easily! Say you http://www.devhut.net/2013/12/16/vba-automate-internet-explorer-to-log-into-a-website-automatically/ wanted to automate logging into your GMail account at the click http://stackoverflow.com/questions/20957649/on-error-goto-multiple-times of a button, nothing could be easier. Below are 2 different approach to do exactly that: Function OpenGMail1() Dim IE As Object 'SHDocVw.InternetExplorer On Error Resume Next Set IE = GetObject(, "InternetExplorer.Application") 'Bind to existing instance of Internet Explorer If Err.Number <> 0 Then 'Could not error handling get instance of Excel, so create a new one Err.Clear Set IE = CreateObject("InternetExplorer.Application") End If On Error GoTo Error_Handler With IE .Navigate "https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en" .Visible = True 'True/False Do While .Busy Or .readyState <> 4: DoEvents: Loop End With With IE.Document.Forms(0) 'gaia_loginform .elements(10).Value = "MyGMailEmailAddress" 'Email .elements(11).Value = "MyPassword" 'Passwd .elements(12).Click 'signIn Do While IE.Busy Or internetexplorer.application error handling IE.readyState <> 4: DoEvents: Loop 'Continue now that we are logged in '... End With Error_Handler_Exit: On Error Resume Next Set IE = Nothing Exit Function Error_Handler: MsgBox "The following error has occured." & vbCrLf & vbCrLf & _ "Error Number: " & Err.Number & vbCrLf & _ "Error Source: OpenGMail1" & vbCrLf & _ "Error Description: " & Err.Description, _ vbCritical, "An Error has Occured!" Resume Error_Handler_Exit End Function Function OpenGMail2() Dim IE As Object 'SHDocVw.InternetExplorer Dim HTMLDoc As Object Dim EmailCtl As Object Dim PwdCtl As Object Dim SubmitCtl As Object On Error Resume Next Set IE = GetObject(, "InternetExplorer.Application") 'Bind to existing instance of Excel If Err.Number <> 0 Then 'Could not get instance of Excel, so create a new one Err.Clear Set IE = CreateObject("InternetExplorer.Application") End If On Error GoTo Error_Handler With IE .Navigate "https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en" .Visible = True 'True/False Do While .Busy Or .readyState <> 4: DoEvents: Loop End With Set HTMLDoc = IE.Document Set EmailCtl = HTMLDoc.getelementbyid("Email") EmailCtl.Value = "MyGMailEmailAddress" S
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up On Error Goto: Multiple times up vote 1 down vote favorite 1 I'm using a macro to get infos from a website: Sub get_prices() Dim IE As Object Dim URL As String Dim cell As Range Dim rng As Range Set rng = Range("A2", Range("A1048576").End(xlUp)) Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True For Each cell In rng.Cells comeco: On Error GoTo pau: URL = Cells(1, 2) & cell.Text & "?utm_source=teste" & Rnd IE.Navigate (URL) Do DoEvents Loop Until IE.READYSTATE = 4 Application.Wait (Now + TimeValue("00:00:05")) Cells(cell.Row, 2) = Mid(IE.Document.GetElementById("ctl00_Conteudo_ctl01_precoPorValue").innertext, 3) Cells(cell.Row, 2).Formula = _ WorksheetFunction.Substitute(WorksheetFunction.Substitute(Cells(cell.Row, 2), ".", ""), ",", ".") Next pau: IE.Quit Set IE = Nothing Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True GoTo comeco: End Sub The problem is that from time to time, my Excel kind of "loses the IE object", and I get the error message "THE OBJECT IS REQUERIED" in the following line: Cells(cell.Row, 2) = Mid(IE.Document.GetElementById("ctl00_Conteudo_ctl01_precoPorValue").innertext, 3) Normally, I just debug the code, and make a new line, like: Set IE = CreateObject("InternetExplorer.Application") and then I resume the macro. Bud I'd like to make something more robust, something that everytime an error occurs, it closes the IE and then reopen it. I'm trying to use on error goto But it only works the first time a error occurs, if it happens again it wont go to the error section. Can anyone help me? vba excel-vba share|improve this question edited Jan 7 '14 at 12:31 asked Jan 6 '14 at 19:25 Fabio Rebelo 54312 Where is the On Error Goto ... statement? If it's only catching the error the first time, it may be that the Resume statement isn't set up correctly. –Blackhawk Jan 6 '14 at 20:01 @Blackhawk, I put comeco: On Error Goto pau: in the beggining, and them at the end of the code I did it: pau: IE.Quit Set IE = CreateObject("InternetExplorer.Application")` goto: comeco –Fabio Rebelo Jan 6 '14 at 20:27 1 Remove the comeco: and replac