Category Archives: Internet Explorer Automation

Web Browser Control – Restricted This File From Showing Active Content

So, I’ve been working on putting together a few Slider control options and wanted to provide a Web based solution as Sliders have long existed in HTML and are far more customizable since everything can be configured via CSS!

It took but a quick Google search to find an IE compatible Slider that I wanted to incorporate into a ‘Legacy’ Web Browser control.

I quickly created a stand-alone HTML file, tested it in IE to ensure all was well and it worked perfectly!

I was ready to now bring it into my Access database!  Setup the control source, test it out and what do I get?!

Continue reading

Internet Explorer Automation Dead?

RIP IE

The writing appears to be on the wall for Internet Explorer, and by extension Internet Explorer automation.

Internet Explorer 11 desktop application will be retired and go out of support on June 15, 2022Microsoft - Windows Blog
Microsoft Edge with IE mode is officially replacing the Internet Explorer 11 desktop application on Windows 10. As a result, the Internet Explorer 11 desktop application will go out of support and be retired on June 15, 2022Microsoft - Tech Community

So if you have application utilizing Internet Explorer automation, start planning now!

Continue reading

VBA – Automate Internet Explorer to Log into a Website Automatically

Ever wanted to automate logging into a website. Well you can automate Internet Explorer to perform such tasks quite easily!

Say you wanted to automate logging into your GMail account at the click 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 GoTo Error_Handler
    Set IE = CreateObject("InternetExplorer.Application")

    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 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 occurred." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: OpenGMail1" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occurred!"
    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 GoTo Error_Handler
    Set IE = CreateObject("InternetExplorer.Application")

    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"
    Set PwdCtl = HTMLDoc.getelementbyid("Passwd")
    PwdCtl.Value = "MyPassword"
    Set SubmitCtl = HTMLDoc.getelementbyid("signIn")
    SubmitCtl.Click

    Do While IE.Busy Or IE.readyState <> 4: DoEvents: Loop

    'Continue scrapping here
    '...

Error_Handler_Exit:
    On Error Resume Next
    Set SubmitCtl = Nothing
    Set PwdCtl = Nothing
    Set EmailCtl = Nothing
    Set HTMLDoc = Nothing
    Set IE = Nothing
    Exit Function

Error_Handler:
    MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
            "Error Number: " & Err.Number & vbCrLf & _
            "Error Source: OpenGMail2" & vbCrLf & _
            "Error Description: " & Err.Description, _
            vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Function

Simple as can be.

These procedures can both be easily adapted to pretty much work with any website by simply changing the Form/Element # or the ElementId for the controls you are trying to bind to.

No Binding To Existing Instances
Typically I would try to bind to an existing instance of IE to automate, as it is more efficient, by doing something along the lines of:

    On Error Resume Next
    Set IE = GetObject(, "InternetExplorer.Application")    'Bind to existing instance of Internet Explorer
    If Err.Number <> 0 Then
        'Could not get instance of IE, so create a new one
        Err.Clear
        Set IE = CreateObject("InternetExplorer.Application")
    End If
    On Error GoTo Error_Handler

Sadly, GetObject() does not work with Internet Explorer Automation and returns:

Run-time error ‘429’:
ActiveX component can’t create object

So there is no need for this block of code and instead we simply simplify things to only use CreateObject, by doing:

    On Error GoTo Error_Handler
    Set IE = CreateObject("InternetExplorer.Application")

I am not a proponent of Internet Explorer (IE) because of major security issues and slower than average performance. That said, sadly, you cannot automate other browsers in such a manner, at least not that I am aware of. So IE does have a serious leg up on the competition when it comes to this type of thing!