Cycle thru radio buttons in web form with VBA

Dude

Board Regular
Joined
Jan 12, 2006
Messages
80
I have some code that logs me into a customer site and i get a large form with a bunch of options that need to be chosen. I have isolated the form I need to use "document.ConsignmentForm()" but it has 6 radio buttons and a submit button.
I have been able to submit the form with the default "Checked Name" button but I cant figure out how to cycle through the other button values eg. RB_RPT2, RB_RPT3, etc. etc. etc.

Have tried all kinds of clumsy floundering around in the dark, wonder if someone can point me to the light ?


Thanks


Code:
function SetDate () {
document.cookie = "frdate=" + document.ConsignmentForm.elements[8].value + ';path=/';
//document.cookie = "frdate=" + document.FORM1.elements[8].value + ';path=/'; 
//document.cookie = "todate=" + document.ConsignmentForm.elements[9].value + ';path=/';
document.cookie = "todate=" + document.ConsignmentForm.elements[8].value + ';path=/';   
}
//--> 
    </script><o:p> </o:p></p>
    <form action="https://portal.pwc.ca/scripts/wgate/" method=POST
    enctype="application/x-www-form-urlencoded">
    <p class=MsoNormal><span style='display:none;mso-hide:all'><INPUT TYPE="hidden" NAME="~PASSWORD[1]"></span><span
    style='display:none;mso-hide:all'><INPUT TYPE="hidden" NAME="~LOGIN[1]"></span><o:p></o:p></p>
    <div align=center>
    <table class=MsoNormalTable border=0 cellspacing=1 cellpadding=0
     style='mso-cellspacing:.7pt'>
<!--- <tr>
			<td class="gNewItem" style="font-size:larger;">Note:</td>
			<td colspan="3"  style="font-weight:bold;color:navy;">The Month-end Stock is as the Mar 01</td>
		</tr> --->
     <tr style='mso-yfti-irow:0'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Stocks </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" CHECKED NAME="RADC_%R%102" VALUE="RB_RPT1"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Receipts </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT2"></p>
      </td>
     </tr>
     <tr style='mso-yfti-irow:1'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Issues </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT3"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Process for payment </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT4"></p>
      </td>
     </tr>
     <tr style='mso-yfti-irow:2'>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Month-end Stock </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT5"></p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal>Previous Month-end Stock </p>
      </td>
      <td style='padding:.75pt .75pt .75pt .75pt'>
      <p class=MsoNormal><INPUT TYPE="radio" NAME="RADC_%R%102" VALUE="RB_RPT5A"></p>
      </td>
     </tr>
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Could you actually post your current VBA code?

And the URL would help too.
 
Upvote 0
I Don't think it would be prudent to actually post the username and password on a public forum but here is what I have so far. I left the commented out variations that I haven't yet deleted. If I leave out any
reference to a value for the radio buttons it will direct me to the first report, but I just can't figure how to change the value. I keep getting an error message "Object doesn't support this property or method".


Code:
Sub PWlogin()
Dim ie As InternetExplorer
Dim PWPage As Object
Dim Form As Object
Dim HtmlDoc As HTMLDocument
Dim RB As Object 'HTMLInputElement


        Set PWPage = CreateObject("WScript.Shell")
        Set ie = New InternetExplorer
        With ie
            .Navigate "https://portal.pwc.ca/portal40/admin/Login.asp?UserID=2&"
            Do While .busy: DoEvents: Loop
            Do While .ReadyState <> 4: DoEvents: Loop
            .Visible = True
           
    With .document.Form()
            .UserName.Value = "*******"
            .Password.Value = "*******"
            .submit
    End With
            Do While .busy: DoEvents: Loop
            Do While .ReadyState <> 4: DoEvents: Loop
            
                    ''''Set HtmlDoc = .document.ConsignmentForm()
                    ''''Set RB = HtmlDoc.Item("RADC_%R%102")
                    ''''RB.Value = "RB_RPT2"

    With .document.ConsignmentForm.Item("RADC_%R%102")
            .Value = "RB_RPT2"
            ie.document.ConsignmentForm().submit
    End With
             Do While .busy: DoEvents: Loop
             Do While .ReadyState <> 4: DoEvents: Loop
            
    End With
Set ie = Nothing
End Sub
 
Upvote 0
So where are you getting the error(s)?

By the way the With End With structure is pretty confusing, it's hard to tell exactly what you are referencing in some of the code.
 
Upvote 0
under your "With .document....."

.RB_RPT2.click
.Submit

naturally, .RB_RPT2 needs to be whatever radio button you have. The .click simulates the mouse click. This has worked for me in the past.
 
Upvote 0
Sorry for the confusion, the first With - End With is on the login page which the redirects to a web portal. The second With - End With is for the ConsignmentForm input. I keep getting the error when I try to assign a value for the radio button. If I comment out the Value = line it submits fine for the default checked name. If I try to assign a value for any of the reports it gives the error message.
 
Upvote 0
you don't want to assign a value to a true/false box, you want to make it true/false. .click should be the key
 
Upvote 0
Dude

Any chance you could find a non-secure site with a similar set of option buttons?

It really helps with this sort of thing to have something to 'play' with.:)

I can't recall if I used VBA to automate option buttons on a webpage, I'll have a look at what code I do have.
 
Upvote 0
Tightwad
I tried
Code:
            With .document.ConsignmentForm.Item("RADC_%R%102")
                .RB_RPT2.Click
                .submit
            End With

And

Code:
            With .document.ConsignmentForm()
                 .RB_RPT2.Click
                .submit
            End With

Each gets me the same error message
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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