CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011

    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

    Option Explicit
    Private Sub ERGLoginbtn_Click()
    Dim IE As Object
        Set IE = CreateObject("InternetExplorer.application")
        IE.navigate ("https://apprenticeshipvacancymatchingservice.lsc.gov.uk/navms/forms/candidate/CandidatesLogin.aspx")
        IE.Visible = True
        While IE.Busy
        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
        While IE.Busy
         '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
    End Sub
    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

    cheers for any help in advance

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)