Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Insert excel cell values to word doc - using VBA
#1
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
Reply
#1
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
Reply
CAA


Forum Jump:


Users browsing this thread: 1 Guest(s)