Hello all
My overall goal seems relatively straightforward - to develop VBA code that gets data from a website.
The specific problem I’m facing arises from the fact that I have to logon to one website (let’s call this page URL-1) and then enter a password on a second, different, website (let’s call this one URL-2).
The navigation from URL-1 to URL-2 (from the logon page to the password page) occurs automatically after clicking a submit button on URL-1. Finally a button click on the password page (URL-2) finally gets me to the data tables.
My specific glitch is that the code stalls on URL #2 where the cursor just sits blinking in the empty password field.
Because my VBA skill level is modest at best, I can only guess at the cause of my problem.
Maybe - the problem starts with the fact that code (see below) is associated URL #1 so that when the Internet Explorer is redirected to URL #2 the code becomes incorrect and will not run.
But right now I’m just guessing at that.
I've been working this issue for more than a week and my www searches have not been, directly, useful.
Incidentally, I've tried to solve this problem by stringing two subs (with different URL specifications) together but I can’t get that to work either.
Any help in developing code that navigates across URL-1 and -2 is appreciated
BobWald
Option Explicit
Public Sub CU_Login_Website()
Dim oBrowser As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = https://www.URL-1.com ‘this URL (URL-1) is the logon page - URL-2 (the password page) is not indicated,
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL 'this is the logon webpage (URL-1)
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.Login.Value = "########" 'submitted on URL-1 (login page)
HTMLDoc.all.Password.Value = "aaaaaaaaa" 'submitted on URL-2 (password page)
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For ' this click appears to elicit the navigation from URL-1 to URL-2
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
'Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub