Use Excel VBA to select a radio button

hansest1

New Member
Joined
Apr 16, 2011
Messages
3
I am a newbie to Excel VBA and am seeking to select a radio button using VBA code.

the Code I have written is simply:

Sub Consolidations()
Dim iLastRow As Integer
Dim Rng As Range
Dim IE As Object

Set IE = CreateObject("Internetexplorer.Application")
On Error GoTo errHandler

With IE
.Visible = True
.navigate "https://loanconsolidation.ed.gov/AppEntry/QuestionAnswerServlet?Button_Pressed_Hid=FirstTime&Language_Hid=english&Process_Flow_Hid=print"

While IE.busy:
DoEvents
Wend

IE.document.question1.Checked = True

End With


This Navigates to the page just fine but doesn't seem to check the radio box. Any suggestions??
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
The question1 radio buttons have on click (without the space) handlers so you have to call the Click method and wait for the page to update. For the other radio buttons, set the Status property. In each case, (0) is the Yes button and (1) is the No button.
Code:
Option Explicit

Const READYSTATE_COMPLETE = 4

Sub Consolidations()
    Dim iLastRow As Integer
    Dim Rng As Range
    Dim IE As Object
    
    Set IE = CreateObject("Internetexplorer.Application")
    
    With IE
        .Visible = True
        .navigate "https://loanconsolidation.ed.gov/AppEntry/QuestionAnswerServlet?Button_Pressed_Hid=FirstTime&Language_Hid=english&Process_Flow_Hid=print"
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        
        .document.all("question1")(1).Click                                 'Choose No
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        
        .document.all("question4")(0).Status = True                         'Choose Yes
    End With

End Sub
 
Upvote 0
Any thoughts on how to select the Continue button, that doesn't seem to be working

<BR> <A href="/AppEntry/apply-online/appindex.jsp"><IMG src="/AppEntry/images/back.gif" border="0" alt="back"></A>    <A href="javascript:UserSelection('continue')"><IMG src="/AppEntry/images/continue.gif" border="0" alt="continue"></A></TD>

I tried .Document.forms(0).Click but that doesn't seem to work.
 
Upvote 0
You can try this.
Code:
Dim frm As Object
 
 ' code to select options etc
 
 ' run this code once above complete
Set frm = IE.document.getelementbyid("questionanswer")
 
frm.submit

Note, if there are any mistakes on the form, eg unanswered question, this will probably display some sort of error page.
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,671
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top