+ Reply to Thread
Results 1 to 7 of 7

Select radio button on website using Excel VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    02-07-2014
    Location
    Miami
    MS-Off Ver
    Excel 2003
    Posts
    18

    Select radio button on website using Excel VBA

    Hello experts,
    I need help to select the "I agree" radio button on a website. I tried many ways found on the Internet but I couldn't get it to work, so I give up and I am here to find a solution.
    The steps are the following:
    -Login (done)
    -Agree the terms (Here is the problem)
    -Start to work (I guess this gonna be easy)

    Here is the code I am using to login (the next page is the Agreement):
    Private Sub Label1_Click()
    If Me.TextBox1.Value = "" Then MsgBox "You must enter a Sender ID.", vbExclamation, "Sender ID is Empty...": Exit Sub
    If Me.TextBox2.Value = "" Then MsgBox "You must enter the Password.", vbExclamation, "Password filed is Empty...": Exit Sub
    
    If Me.TextBox1.Value <> "I CAN'T SHOW THIS" Then
    MsgBox "You entered an incorrect Sender ID.", vbCritical, "Wrong Sender ID..."
    Me.TextBox1.BorderColor = vbRed
    Exit Sub
    Else
    GoTo checkPass
    End If
    
    checkPass:
    If Me.TextBox2.Value <> "I CAN'T SHOW THIS" Then
    MsgBox "You entered the wrong Password.", vbCritical, "Wrong Password..."
    Me.TextBox2.BorderColor = vbRed
    Exit Sub
    Else
    GoTo accessLogin
    End If
    
    accessLogin:
    Set IE = CreateObject("InternetExplorer.Application")
        With IE
            .Visible = True
            .Navigate "https://eapis.cbp.dhs.gov/"
            Do Until .ReadyState = 4
                DoEvents
            Loop
            .Document.all.Item("username").Value = Me.TextBox1.Text
            .Document.all.Item("password").Value = Me.TextBox2.Text
            .Document.forms(0).submit
        End With
    End Sub
    And here is the code I got from the "Inspect Element" of Google Chrome in the webpage:

    <div class="tworadios">	
    	<span class="radio1"><input type="radio" name="agreement" value="1">I agree</span>
    	<span class="radio2"><input type="radio" name="agreement" value="2" checked="checked">I disagree</span>
    	
    	</div>
    This is the code following the above (Is where the "Next" button appears, to agree the terms and continue, but I guess I must use .Document.forms(0).submit to continue):

    <div id="navigation">
    		<span></span>
    		<input class="navbutton" type="image" src="img/btn_next.gif" name="next" value="Next">
    	</div>

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

    Re: Select radio button on website using Excel VBA

    What have you tried to select the radio button?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Select radio button on website using Excel VBA

    Should you really be skipping reading the T&Cs on something like that?

  4. #4
    Registered User
    Join Date
    02-07-2014
    Location
    Miami
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Select radio button on website using Excel VBA

    Hello Norie, I tried the .click procedure but I am not sure how that works in this case, as you can see, the radio buttons does not have an ID so I can't getElementById. Also I tried a Checked procedure. This is my first time manipulating a website using VBA. I don't remember exactly what I tried, I just was googling.

    Hello Kyle123, I work on that site every day, I don't need to read it. I m doing this because I want to automate some procedures in the job.

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

    Re: Select radio button on website using Excel VBA

    You could use getElementsByClassName, and rather than the click method perhaps value or selected (checked?).

  6. #6
    Registered User
    Join Date
    02-07-2014
    Location
    Miami
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Select radio button on website using Excel VBA

    Thank you Noire. Can you write a sample code based on my codes from my first post PLEASE? I am not a VBA expert

  7. #7
    Registered User
    Join Date
    02-07-2014
    Location
    Miami
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Select radio button on website using Excel VBA

    Can someone help me?

+ 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. Excel VBA to select IE radio button
    By amike402 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-20-2014, 03:00 PM
  2. [SOLVED] How to select more than one activeX radio button?
    By Triscia in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-04-2012, 12:07 PM
  3. Prompting User to Select Radio Button
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2011, 06:48 PM
  4. Select All or None of Checkboxes using Radio Button
    By smk224 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2010, 04:53 AM
  5. Pressing one radio button to select another radio button
    By raehippychick in forum Excel General
    Replies: 1
    Last Post: 09-13-2007, 11:30 PM

Tags for this Thread

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