PDA

Click to See Complete Forum and Search --> : How do I add Excel data to a word document


Colex
Apr 29th, 2006, 10:02 AM
I create a document from a template that inputs (via a userform) various data. Within this data if a reference which relates to the row value of further data in a excel spreadsheet. How do I go about adding this data automatically to the document once the row value has been stated?

Thanks

RobDog888
Apr 30th, 2006, 12:22 AM
Add a reference to Excel in your VBA IDE Project References.

Then open the workbook and read/write the cells/data you want.

Option Explicit

Private Sub Command1_Click()
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook

Set oApp = New Excel.Application
Set oWB = oApp.Workbooks.Open("C:\Book1.xls")
MsgBox oWB.Cells(1, 1)

oWB.Close SaveChanges:=True
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub