Automation Runtime error with "InternetExplorerMedium"

programsam

Board Regular
Joined
Feb 10, 2016
Messages
77
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.
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,013
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:

Forum statistics

Threads
1,082,587
Messages
5,366,484
Members
400,894
Latest member
frog9000

Some videos you may like

This Week's Hot Topics

Top