Computer Aided Automation

Full Version: Insert excel cell values to word doc - using VBA
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Open word, insert a label from Design mode (in developer tab)

Insert Button

Double click on button, in VBA editor; go to Tools -> References-> tick Microsoft excel 
objects and controls (similar)

Add below code (for button)

Private Sub CommandButton1_Click()
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open("d:\excel.xlsx")
ThisDocument.prjno.Caption = exWb.Sheets("Sheet1").Cells(6, 2)
Set exWb = Nothing
End Sub