0

I am VERY new to VBA and have been watching a ridiculous amount of youtube videos (specifically wise owl tutorials) and have searched here to try and find the answer to my question. I am writing a code to automate part of my job. I have the code to log in to a site that I can't share because I work with classified docs but I will share what I can. Here is the code so far...

Sub Login_and_click_link()

Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLDiv As MSHTML.IHTMLElement
Dim HTMLAs As MSHTML.IHTMLElementCollection
Dim HTMLA As MSHTML.IHTMLAnchorElement

'Open Internet Explorer and Navigate to PDDA
With IE
    .Visible = True
    .Navigate "http://.TheWebsiteINeed.com"
End With

'Loop until PDDA page has fully loaded
    Do While IE.ReadyState <> READYSTATE_COMPLETE
    Loop

'Search DOM for element by ID and input username
Set HTMLDoc = IE.Document
Set HTMLInput = HTMLDoc.getElementById("userName")
HTMLInput.Value = Worksheets("sheet1").Range("letternumber").Text

'Search DOM for an element by ID and input password
Set HTMLInput = HTMLDoc.getElementById("Password")
HTMLInput.Value = Worksheets("sheet1").Range("letternumber").Text

'Search DOM for element by ID and click submit
Set HTMLInput = HTMLDoc.getElementById("submit")
HTMLInput.Click
    
'Navigate to the tab I need
??????

End Sub

There are two links on the page, each will take me to the same page that I need next. So whichever is easier to write code for you can use.

The link at the top is this(within a tr tag):

<span> class="topNavoff" style="cursor: hand;" onmouseover="window.status='Process 
Management';this.className='topNavon';" 
onmouseout="window.status='';this.className='topNavoff';" 
onclick="setTask('pmMain');">Process</span>

The link at the bottom is this (within a p tag):

<span> class="contentSubtitleLink" id="process" style="cursor: hand;" 
onmouseover="window.status='Process Management';" onmouseout="window.status='';" 
onclick="setTask('pmMain');">Process</span>

Let me know if there is anything I can send to help make this more clear. ANY help would be GREATLY appreciated!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MattyRB
  • 1
  • 1
  • There's a javascript function `setTask('pmMain');` that's called in the `onclick` attribute. Try `execScript` (see this [answer](https://stackoverflow.com/questions/31521205/how-to-find-and-call-javascript-method-from-vba)) and see if it works after the click – Raymond Wu Sep 30 '21 at 23:09
  • Good to know! It doesn't work always in my experience (and requires further debugging and action) @MattyRB – Raymond Wu Oct 01 '21 at 12:11
  • @Raymond Wu Do you know how to do the same thing in chrome using selenium? – MattyRB Oct 05 '21 at 17:23
  • Personally i don't use selenium but I'm sure there are plenty of answers if you google for it. – Raymond Wu Oct 05 '21 at 17:47
  • @RaymondWu I've been trying all day to no avail. If you see anything, could you please post a link here? Thank you – MattyRB Oct 05 '21 at 18:24
  • why not ask a new question? – Raymond Wu Oct 05 '21 at 23:01

0 Answers0