VBA Script to send form information to a new line in excel sheet on same drive

posfog

Board Regular
Joined
Jun 2, 2009
Messages
171
Morning All,
What i am trying to do is create a single web page that has text fields and radio buttons to allow a user to input data using a touch screen prior to hitting a submit button and for that data to be sent to a single excel file.

I found the following code during my google research on the matter which gives me four text fields that i can enter data on and which works with it sending it to a new line each time on the same excel file.

How ever i wish to understand this code to allow me to create a more detailed form with a text boxes, radio buttons and checkboxes.

Code:
<!DOCTYPE html>
<html>
<head>
******** language="vbscript" type="text/vbscript">
Sub Sample()
Dim iRow
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("home/Book1.xlsx")
'Document.GetElementsByName("fname")(0).Value="C#"
'Document.GetElementsByName("lname")(0).Value="Corner"
'Document.GetElementsByName("Add1")(0).Value="Tamilnadu"
'Document.GetElementsByName("Add2")(0).Value="Coimbatore"
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("fname")(0).Value
.Cells(iRow, 2).value=Document.GetElementsByName("lname")(0).Value
.Cells(iRow, 3).value=Document.GetElementsByName("Add1")(0).Value
.Cells(iRow, 4).value=Document.GetElementsByName("Add2")(0).Value
MsgBox "Data Added Sucessfully",vbinformation
Document.GetElementsByName("fname")(0).Value=""
Document.GetElementsByName("lname")(0).Value=""
Document.GetElementsByName("Add1")(0).Value=""
Document.GetElementsByName("Add2")(0).Value=""
End With
objWorkbook.save
objWorkbook.close
Set objWorkbook = Nothing
Set objExcel = Nothing
End Sub
*********>

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

<center>

First name:<br>
<input type="text" name="fname" Value=""><br>
Last name:<br>
<input type="text" name="lname" Value=""><br>
Address1:<br>
<input type="text" name="Add1" Value=""><br>
Address2 :<br>
<input type="text" name="Add2" Value=""><br>
<br>
<input type="button" *******="Sample()" value="Submit" /><br>
</center>
</fieldset>
</form>
</body>
</html>

Also i am not too sure what the values are for at the ends of the following line of coding? Do the words in "" mean anything to anyone??

'Document.GetElementsByName("fname")(0).Value="C#"
'Document.GetElementsByName("lname")(0).Value="Corner"
'Document.GetElementsByName("Add1")(0).Value="Tamilnadu"
'Document.GetElementsByName("Add2")(0).Value="Coimbatore"

Hope there is someone on this forum who is able to help at all.

I have posted this in other HTML stlye forums but had no luck at all (hope this is ok?)
Kind Regards
P
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

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