Interact with Webpage from Outlook

I have the following code which successfully opens a hyperlink in internet explorer from an email in Outlook.

My next question is how do I interact with the webpage?

For example I would like to select option 83 from ID "ctl00_cph_MAIN_ddlHCLaction" which is a dropdown.

I have tried
oIE.document.GetElementbyID("ctl00_cph_MAIN_ddlHCLaction").value = 83

Open in new window

but I get the error

'Run-time error '-2147467259 (80004005)': method 'document' of object 'IWebBrowser2' failed.'

Sub macro()

Dim regex
    Set objOL = CreateObject("Outlook.Application")
    Set NewMail = objOL.ActiveExplorer.Selection.Item(1)
    NewMail.Display
    res = NewMail.Body
    
    Set regex = CreateObject("VBScript.RegExp")

    With regex
        .Global = False
        .MultiLine = False
        .IgnoreCase = True
        .Pattern = "HYPERLINK ""([^""]+?)""Click here to access enquiry"
    End With
    Set mtches = regex.Execute(res)
        If mtches.Count > 0 Then
            strHL = mtches(0).submatches(0)
            Set oIE = New InternetExplorerMedium
            oIE.navigate strHL, CLng(2048)
            oIE.Visible = True
        End If
End Sub

Open in new window

J PAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

J PAuthor Commented:
Rgonzo1971 are you available to help?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
The DOM (document) is not available (yet). That can mean a lot - you were not waiting long enough to allow the page to be rendered, for example.
Before performing any processing of the web page, you should run
Do While oIE.ReadyState = 4: DoEvents: Loop  

Open in new window

to make sure the page is fully loaded. That might be all you need. If not, set a breakpoint at the line you are accessing the page, and test in Immediate Window, e.g. with  ? oIE.document.ReadyState
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.