December 2nd, 2011, 06:00 AM
Object variable or With Block variable not set... VBA Excel Help :(
Hey there guys, I know you must have seen this 100 times before, but I cannot for the life of me see where I have gone wrong. The first time the code is executed, it loads IE on the page desired, then throws up the error:
Runtime error '91'
Object variable or With Block variable not set
Then if I run it again immediatley afterwards, it works fine... the error is thrown up on the line in bold, so I would assume that it would be the same for the following 3 lines.... something I have done somewhere must be wrong, it's probably something really simple, but hey, i'm an amateur LOL
Private Sub ERGLoginbtn_Click()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.document.getElementById("ctl00_ContentBody_LoginControl1_UsernameTextBox").Value = "XXXXX"
IE.document.getElementById("ctl00_ContentBody_LoginControl1_PasswordTextBox").Value = "XXXXX"
IE.document.all("ctl00$ContentBody$LoginControl1$LoginButton").Click 'click the login button
'any more code
'if the user closes the web page then you don't need the quit
'set IE to nothing at the end of macro
Set IE = Nothing
cheers for any help in advance
December 6th, 2011, 01:44 PM
Re: Object variable or With Block variable not set... VBA Excel Help :(
Most likely the code is executing before the page is ready.
Always use [code][/code] tags when posting code.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!