gitmeto
Board Regular
- Joined
- Nov 24, 2021
- Messages
- 60
I am looking at creating a web page that contains a userform where the data captured by the userform is then saved to a specific table in Excel. I found some code online that almost gets me there but instead of a specific table, it places it on a sheet. I would like to specify the table that the data from the userform is saved to. I am thinking this is an easy modification.
Any and all assistance is greatly appreciated!
Form Code Link
Any and all assistance is greatly appreciated!
VBA Code:
<! DOCTYPE html>
<Html>
<Head>
<script language="vbscript" type="text/vbscript">
Sub Sample ()
Dim iRow
Set objExcel = CreateObject ("Excel. Application")
Set objWorkbook = objExcel.Workbooks.Open ("C:\Users\Karthikeyan.K\Desktop\Book1.xlsx")
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
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
</script>
<style type="text/css">
fieldset {
border: #00cc00 2px solid;
padding: 10px;
color: green;
</style>
<body
<form>
<fieldset>
<legend>Csharpcorner</legend>
<center>
<img src="C:\Users\Karthikeyan.K\Desktop\Add-Male-User.png" alt="Mountain View"><br>
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" onclick="Sample()" value="Submit" /><br>
</center>
</fieldset>
</form>
</body>
</html>
Form Code Link