How do I add Excel data to a word document
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
Re: How do I add Excel data to a word document
Add a reference to Excel in your VBA IDE Project References.
Then open the workbook and read/write the cells/data you want.
VB Code:
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