VBA code Runtime error 91: Object variable or With block variable not set .

DHKMA

New Member
Joined
Mar 25, 2019
Messages
1
Hi,

I am new to VBA coding and I am trying to automate the webpage login process which has username and password but unfortunately the code shows the runtime error-Object variable or With block variable not set. Please help me to solve this case. Please find below the VBA code and source code.

Code:
Sub Test()

    Const cURL = "https://www.mouser.de/MyMouser/MouserLogin.aspx?qs=0gZ0gv0KDwuMOi23mhrom5dftrtAODwYFMqEFQoZe7k%3d" 'Enter the web address here
    Const cUsername = "XXX"
    Const cPassword = "XXXX"
    
    Dim IE As InternetExplorer
    Dim doc As HTMLDocument
    Dim LoginForm As HTMLFormElement
    Dim UserNameInputBox As HTMLInputElement
    Dim PasswordInputBox As HTMLInputElement
    Dim SignInButton As HTMLInputButtonElement
    Dim HTMLelement As IHTMLElement
    Dim qt As QueryTable
    
    Set IE = New InternetExplorer
    
    IE.Visible = True
    IE.Navigate cURL
    
    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
    
    Set doc = IE.Document


    
    Set LoginForm = doc.forms(0)
    


    Set UserNameInputBox = LoginForm.elements("ctl00_ContentMain_login_login_UserNameLabel")
    UserNameInputBox.Value = cUsername
    




    Set PasswordInputBox = LoginForm.elements("ctl00_ContentMain_login_login_PasswordLabel")
    PasswordInputBox.Value = cPassword
    
    Set SignInButton = LoginForm.elements("ctl00_ContentMain_login_login_LoginButton")
    SignInButton.Click
            
    
    
    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
    
    End Sub

HTML:
<label for="ctl00_ContentMain_login_login_UserName" id="ctl00_ContentMain_login_login_UserNameLabel" class="bold">Username:</label><br/>
<label for="ctl00_ContentMain_login_login_Password" id="ctl00_ContentMain_login_login_PasswordLabel" class="bold">Password:</label><br/>
<input type="submit" name="ctl00$ContentMain$login$login$LoginButton" value="Log In" *******="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentMain$login$login$LoginButton", "", true, "login", "", false, false))" id="ctl00_ContentMain_login_login_LoginButton" class="button" />

Thanks,
DHKMA.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,518
Messages
6,119,985
Members
448,935
Latest member
ijat

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