VBA Script Document.GetElementsByName issue

posfog

Board Regular
Joined
Jun 2, 2009
Messages
170
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>
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Watch MrExcel Video

Forum statistics

Threads
1,089,761
Messages
5,410,273
Members
403,305
Latest member
tray2014

This Week's Hot Topics

Top