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.
Thanks,
DHKMA.
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.