Excel Help

A

alihussain19

Hi,
I am not sure if someone could help me in this....
I have a VB form in word with about 5 fields and when I submit it
need to know how to start a an Excel file and enter the data from th
text boxes on that form to the Excel sheet at the first empt
row.....Any Help Will be Appriciated...
Thank
 
B

Bob Phillips

Something like

Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open "C:\myTest\volker1.xls"
Set xlWS = xlWB.Activesheet
iLastRow = xlWS.Cells(Rows.Count).End(xlUp).Row
With xlWS
.Cells(iLatRow+1,"A").Value = TextBox1.Text
.Cells(iLatRow+1,"B").Value = TextBox2.Text
.Cells(iLatRow+1,"C").Value = TextBox3.Text
.Cells(iLatRow+1,"D").Value = TextBox4.Text
.Cells(iLatRow+1,"E").Value = TextBox5Text
End With

If you want to see the XL app, then add

xlApp.Visible = True

to save the workbook

xlWB.Save

at the end, to quit Excel

xlApp.Quit

You will also need to set a reference to Excel library, VBE
Tools>References.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Top