Automation Runtime error with "InternetExplorerMedium"

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Alright folks,

I'm trying to set up a file that pulls up a company Intranet via IE, fills in a few fields and then hits "go" to populate a list. It's triggering an "automation" runtime reror because of the Set doc = IE.document line (Line 7) and I suspect is has something to do with "InternetExplorerMedium" but I HAVE to have that setting to maintain IE security.

I'm trying to figure out how to fix this error so I can proceed. The code that I have thus far is as follows:

Code:
Sub fillForm()

'Establish IE
Dim IE As InternetExplorer
Set IE = New InternetExplorerMedium
Dim doc As HTMLDocument
Set doc = IE.document [COLOR=#ff0000][B]<----getting runtime automation error here[/B][/COLOR]


'Change Settings


Dim activeLink As String


activeLink = "http://thelink"


'Open IE and Navigate to web form
With IE


    .navigate activeLink
    .Visible = True


   'Loop to wait until page loads
   
Do Until IE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop


End With


'Find IE Form


Dim iframeDoc As MSHTML.HTMLDocument
Set iframeDoc = doc.frames("cAF").frames("iWA") '.document




'Fill out Form


Dim cusType, prSeg, cN As String


cusType = ThisWorkbook.Sheets("data").Range("P2").Value
prSegt = ThisWorkbook.Sheets("data").Range("P3").Value
cN = ThisWorkbook.Sheets("data").Range("P4").Value




With IE.document


    iframeDoc.getElementsById("__xmlview1--cusType").Value = cusType
    iframeDoc.getElementsById("__xmlview1--prSeg").Value = prSeg
    iframeDoc.getElementsById("__xmlview1--cN").Value = cN


'Submit Form
    iframeDoc.getElementsById("__xmlview1--idFilterbar-btnGo").Value.Click


End With




'Call macro to pull results




End Sub

Any assistance you can provide is much appreciated.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try assigning IE.Document to doc after navigating to your website, and the page has been loaded. By the way, I would also suggest that you check the busy status, in addition to the ready state. Here's an example...

Code:
Option Explicit

Sub test()


    'Set a reference (VBE > Tools > References) to the following libraries:
    '   1) Microsoft Internet Controls
    '   2) Microsoft HTML Object Library
    
    Dim IE As New SHDocVw.InternetExplorer
    Dim HTMLDoc As New MSHTML.HTMLDocument
    
    With IE
        .Visible = True
        .navigate "https://www.google.com"
        Do While .Busy Or .readyState <> READYSTATE_COMPLETE
            DoEvents
        Loop
    End With
    
    Set HTMLDoc = IE.document
    
    'etc
    '
    '
    
    Set IE = Nothing
    Set HTMLDoc = Nothing
    
End Sub

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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