(Solved) – Using VBA to click a javascript link, get “object required” error


I am attempting to access a website on IE using VBA to pull a report of the previous weeks transactions. I was able to login and navigate to the report page. However, when I try to click a link for an advanced search I get the error “Object Required”

Below is the HTML I have isolated as belonging to the link:


Specifically, I am trying to select the “moreOptions” item. I have also tried selecting based on the “mouseover” class with no luck. I also tried to create a saved report that I could just click based on the class and ID, the HTML for this search is below:

Prev Week ACH

I am using the below VBA to access the website and navigate to the page I need. The code errors out when I try to pull the Element “moreOptions”. I built in a 20 second wait time on the page that doesn’t work in case the link wasn’t available yet to no avail. I have gone as high as 1 minute with no results.

Sub login1()
  Dim IE As Object
  Dim HTMLDoc As Object
  Dim objCollection As Object
  Dim allHREFs As New Collection

  Const navOpenInNewTab = &H800
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "https://www.treasury.pncbank.com/idp/esec/login.ht"

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

  Set HTMLDoc = IE.Document

  With HTMLDoc
  HTMLDoc.getElementById("txtUserID").value = "XXXX"
  HTMLDoc.getElementById("txtOperID").value = "XXXXXX"
  HTMLDoc.getElementById("txtPwd").value = "XXXXXX"
  End With

  Set objCollection = IE.Document.getElementById("loginFormButton")

Do While IE.Busy Or IE.readyState <> 4: Loop
Application.Wait (Now   TimeValue("0:00:10"))
   Set objCollection = IE.Document.getElementById("IR")
  Application.Wait (Now   TimeValue("0:01:00"))
   Set objCollection = IE.Document.getElementById("moreOptions")
  Do While IE.Busy Or IE.readyState <> 4: Loop
End Sub

Any help here would be greatly appreciated. Please let me know if you need additional details. As it is a banking website I will not be able to provide login credentials but let me know if you need more of the HTML code.

Leave a Reply

Your email address will not be published. Required fields are marked *