I'm not sure what the Context menu is and as I mentioned in my previous e-mail you cannot directly interact with the menubar but there are other ways round. Unfortunately I've yet to find a decent resource on how to do this properly so all of this is stuff I've learnt via trail and error - there may be better ways of doing things.
The attached is a stripped down version of a bit of code I use to log onto internet banking (less passwords!). It demonstrates a lot of the tricks I've learnt on manipulating IE via VBA. You'll need to reference two libraries before this will work - they are MS HTML Object Library (MSHTML.TLB) and MS Internet Controls (shdocvw.dll). You can reference libraries by selecting Tools -> References... in the VBE.
Code:
Option Explicit
Sub RunAbbeyLogin()
Dim IE As SHDocVw.InternetExplorer
' Login in to the Abbey website
Set IE = AbbeyLogin
Set IE = Nothing
End Sub
Private Function AbbeyLogin() As SHDocVw.InternetExplorer
Dim IE As SHDocVw.InternetExplorer
Dim htmlDoc As MSHTML.HTMLDocument
Dim bReturn As Boolean
' Open up Internet Explorer
Set IE = New SHDocVw.InternetExplorer
IE.Visible = True
IE.navigate "https://myonlineaccounts2.abbeynational.co.uk/ffStatic/html/logon.html"
' Wait for page to load
WaitForLoad IE
' Get the HTML Document
Set htmlDoc = IE.document
' Log into the site
Call Login(htmlDoc, IE)
' Return the Internet Explorer instance
Set AbbeyLogin = IE
End Function
Private Sub Login(hDoc As MSHTML.HTMLDocument, IExp As SHDocVw.InternetExplorer)
' Logs into the first Login page
' using UserID and Password
Dim hCol As MSHTML.IHTMLElementCollection
Dim hInp As MSHTML.HTMLInputElement
Dim bReturn As Boolean
Const cstrPID As String = ""
Const cstrPasscode As String = ""
Const cstrRegNo As String = ""
Application.Wait (Now + TimeValue("00:00:03"))
' Get the collection of all input elements
Set hCol = hDoc.getElementsByTagName("input")
' Loop though each input element and find the Customer number input box
For Each hInp In hCol
' Put the ID, passcode and registration number into the relevant boxes
If hInp.ID = "pid" Then hInp.Value = cstrPID
If hInp.ID = "passcode" Then hInp.Value = cstrPasscode
If hInp.ID = "ern" Then hInp.Value = cstrRegNo
Next hInp
' Loop though each input element and find the Submit button
For Each hInp In hCol
' If its the Submit button then click it
If hInp.ID = "dblclk" Then
hInp.Click
Exit For
End If
Next hInp
' Dereference our variables
Set hCol = Nothing
Set hInp = Nothing
' Wait for the next page to load
WaitForLoad IExp
' Nagvigate to the account page
bReturn = ClickLink("account number 0", hDoc, IExp)
End Sub
Private Function ClickLink(LinkText As String, hDoc As MSHTML.HTMLDocument, IExp As SHDocVw.InternetExplorer) As Boolean
' Simulates clicking a link with the input LinkText on the open webpage
Dim hCol As MSHTML.IHTMLElementCollection
Dim hAnch As MSHTML.HTMLAnchorElement
Dim Ans As Boolean
Ans = False
' Get the collection of links on the page
Set hCol = hDoc.getElementsByTagName("a")
' Find the one specifying which characters we need and pull them out
For Each hAnch In hCol
If InStr(1, hAnch.innerHTML, LinkText, vbBinaryCompare) > 0 Then
hAnch.Click
Ans = True
Exit For
End If
Next hAnch
' Dereference our variables
Set hAnch = Nothing
Set hCol = Nothing
' Wait for page to load
If Ans Then WaitForLoad IExp
ClickLink = Ans
End Function
Private Sub WaitForLoad(IExp As SHDocVw.InternetExplorer)
' Wait for page to load before continuing
Dim sngTime As Single
Const MaxTime As Integer = 10
sngTime = Timer
' Wait until the webpage is doing something ...
Do Until IExp.readyState <> READYSTATE_COMPLETE
DoEvents
If Timer > sngTime + MaxTime And Left(IExp.StatusText, 4) = "Done" Then Exit Sub
Loop
' ... and then wait for it to finish
Do Until IExp.readyState = READYSTATE_COMPLETE
DoEvents
If Timer > sngTime + MaxTime And Left(IExp.StatusText, 4) = "Done" Then Exit Sub
Loop
End Sub