23-11-2019, 07:19 AM
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)
exWb.Close
Set exWb = Nothing
End Sub
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)
exWb.Close
Set exWb = Nothing
End Sub