VBA Script Document.GetElementsByName issue

posfog

Board Regular
Joined
Jun 2, 2009
Messages
171
Hi All,
I am trying to approach this from a different angle, the below code is a watered down version of what i ask trying to create, where a form is used by a single use on a windows machine running IE where the output of the form sends the data to a single excel sheet.

The text box works fine and sends the data across every time, but the Radio button and Check Boxes dont work at all.
Does the "Document.GetElementsByName" work for Radio buttons and Check Boxes at all???

Regards
P


<html>
<head>
******** language="vbscript" type="text/vbscript">
Sub Sample()
Dim iRow
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\ssims1\Desktop\TEST.xlsx")
'Document.GetElementsByName("SerialNumber")(0).Value="
'Document.GetElementsByName("Variant")(0).Value="
'Document.GetElementsByName("Caps-0")(0).Value="
'Document.GetElementsByName("Caps-2")(0).Value="1"


objExcel.Application.Visible = True
objWorkbook.Windows(1).Visible = True
set XlSheet =objWorkbook.Sheets(1)
XlSheet.Activate
iRow = 1
With objExcel
Do While .Cells(iRow, 1).value <> ""
.Cells(iRow, 1).activate
iRow = iRow + 1
Loop


.Cells(iRow, 1).value=Document.GetElementsByName("SerialNumber")(0).Value
.Cells(iRow, 2).value=Document.GetElementsByName("Variant")(0).Value
.Cells(iRow, 3).value=Document.GetElementsByName("CAPS-0")(0).Value
.Cells(iRow, 4).value=Document.GetElementsByName("CAPS-1")(0).Value
.Cells(iRow, 5).value=Document.GetElementsByName("CAPS-2")(0).Value




MsgBox "Data Added Sucessfully",vbinformation


Document.GetElementsByName("SerialNumber")(0).Value=""
Document.GetElementsByName("Variant")(0).Value=""
Document.GetElementsByName("CAPS-0")(0).Value="1"
Document.GetElementsByName("CAPS-1")(0).Value="1"
Document.GetElementsByName("CAPS-2")(0).Value="1"




End With
objWorkbook.save
objWorkbook.close
Set objWorkbook = Nothing
Set objExcel = Nothing
End Sub
*********>


******>
<form>
<fieldset>






<!-- Form Name -->
<legend>Form Name</legend>


<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Serial Number</label>
<div class="col-md-4">
<input id="textinput" name="SerialNumber" type="text" placeholder="SerialNumber" class="form-control input-md" required="">
</div>
</div>




<BR>
<BR>


<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="Variant">Variant</label>
<div class="col-md-4">
<div class="radio">
<label for="Variant-0">
<input type="radio" name="Variant" id="Variant-0" value="NS" checked="checked">
NS
</label>
</div>
<div class="radio">
<label for="Variant-1">
<input type="radio" name="Variant" id="Variant-1" value="EW">
EW
</label>
</div>
</div>
</div>




<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="CAPS">CAPS TITLE</label>
<div class="col-md-4">
<BR>


<BR>

<div class="checkbox">
<label for="CAPS-0">
<input type="checkbox" name="CAPS" id="CAPS-0" value="1">
Bottom Nipple
</label>
</div>
<div class="checkbox">
<label for="CAPS-1">
<input type="checkbox" name="CAPS" id="CAPS-1" value="1">
Breather Pipe Red internal
</label>
</div>
<div class="checkbox">
<label for="CAPS-2">
<input type="checkbox" name="CAPS" id="CAPS-2" value="1">
Clear Fuel Cap
</label>
</div>









<br>
<input type="button" *******="Sample()" value="Add Record" />
</p>
<p> </p>



</p>
</center>
</fieldset>
</form>
</body>
</html>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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