Secure website requires login on one webpage and then redirects the browser to a second URL where the password information must be submitted.

BobWald

New Member
Joined
Aug 19, 2014
Messages
6
Hello all

My goal is to download my data from a web site that requires both a login and a password.

My problem is that the login and password fields are on separate websites (login is on URL #1 while the password field is on URL #2). Clicking the submit button on URL #1 redirects the Browser to URL #2.

My specific glitch is that the Excel VBA code (see below) stalls with the blinking cursor in the empty password field on URL #2.

I believe my problem is related to the fact that my code is associated with URL #1 and will not run when the Browser is redirected to URL #2.

Over the last 3 days I’ve extensively and exhaustively searched the www for help on this issue without success.

My skill level in VBA and website data retrieval is poor to modest so any help on this issue is appreciated.

BobWald

Code:
 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"
    Set oBrowser = New InternetExplorer
        oBrowser.Silent = True
        oBrowser.timeout = 60
        oBrowser.navigate sURL
        oBrowser.Visible = True
Do
' Wait till the Browser is loaded
    Loop Until oBrowser.readyState = READYSTATE_COMPLETE
 
    Set HTMLDoc = oBrowser.Document
 
        HTMLDoc.all.Login.Value = "########"
        HTMLDoc.all.Password.Value = "aaaaaaaaa"
 
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
    If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
 
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
'Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I am totally no star at using VBA to access web sites, but reading your code the following happens:
The first URL gets loaded. When loaded the Login.Value is entered, since there is no password field, the password.value is skipped.
Then the submit button gets pressed
then the macro ends.

Maybe, maybe, the following will work.

Code:
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"
    Set oBrowser = New InternetExplorer
        oBrowser.Silent = True
        oBrowser.timeout = 60
        oBrowser.navigate sURL
        oBrowser.Visible = True
    Do
    ' Wait till the Browser is loaded
    Loop Until oBrowser.readyState = READYSTATE_COMPLETE
 
    Set HTMLDoc = oBrowser.Document
 
    HTMLDoc.all.Login.Value = "########"
 
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
        If oHTML_Element.Type = "submit" Then
            oHTML_Element.Click
            Exit For
        End If
    Next
    ' Here the login has been submitted, waiting for password page
    Do
    ' Wait till the Browser is loaded
    Loop Until oBrowser.readyState = READYSTATE_COMPLETE
 
    Set HTMLDoc = oBrowser.Document
 
    HTMLDoc.all.Password.Value = "aaaaaaaaa"
 
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
        If oHTML_Element.Type = "submit" Then
            oHTML_Element.Click
            Exit For
        End If
    Next
 
Err_Clear:
If Err <> 0 Then
'Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top