+ Reply to Thread
Results 1 to 4 of 4

ERROR 91 - Prolly Minor Issue, but i cant figure it out. - Object variable not set.

  1. #1
    Registered User
    Join Date
    10-04-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    6

    ERROR 91 - Prolly Minor Issue, but i cant figure it out. - Object variable not set.

    Hello guys...

    I new to vba, I think its a minor issue that I have going on.

    When I execute the code below, I get error "91" - Object variable or With block variable not set.

    I need the code to click the button "ENTRAR."

    Going at the page link: http://autorizadorintermedica.starti...spx?ans=359017 you can see the page code. I located the following name for the button: "ctl00$cphBody$LoginButton" - I think this should be correct. I just cant understand why I get an error.

    Thanks a lot in advance!!!

    Sub Test_IAMSPE_()


    Const cURL = "http://autorizadorintermedica.startiss.com.br/Login.aspx?ans=359017"
    Const cUsername = "12345" 'Enter your user name here
    Const cPassword = "99999" 'Enter your Password here


    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


    Set IE = New InternetExplorer

    IE.Visible = True
    IE.Navigate cURL

    'Wait for initial page to load

    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$cphBody$txbUserName")
    UserNameInputBox.Value = cUsername


    Set PasswordInputBox = LoginForm.elements("ctl00$cphBody$txbPassword")
    PasswordInputBox.Value = cPassword


    Set SignInButton = LoginForm.elements("ctl00$cphBody$LoginButton")
    SignInButton.Click ' I GET AN ERROR HERE

    'Wait for the new page to load

    Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

    IE.Visible = True


    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: ERROR 91 - Prolly Minor Issue, but i cant figure it out. - Object variable not set.

    Replace this...
    Set SignInButton = LoginForm.elements("ctl00$cphBody$LoginButton")

    With this...
    Set SignInButton = doc.getElementById("ctl00_cphBody_LoginButton")
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: ERROR 91 - Prolly Minor Issue, but i cant figure it out. - Object variable not set.

    Change LoginForm.elements to LoginForm.all.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    10-04-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2003
    Posts
    6

    SOLVED - Re: ERROR 91 - Prolly Minor Issue, but i cant figure it out. - Object variable n

    Thanks a lot!!
    That's awesome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro issue: Object variable or with block variable not set error
    By utgjmb1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-29-2013, 06:07 AM
  2. Replies: 1
    Last Post: 07-24-2013, 02:45 PM
  3. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  4. Object Variable Not Set Error on Selection object
    By Jean in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-24-2006, 01:50 PM
  5. Object variable issue
    By Tom in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2006, 04:10 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1