I have my DB in Excel and want to consult it to create reports in Word. I have searched and tried different options but none seem to work. Any suggestions would be of great help. I essentially want to paste the content of the second Message box into the word document.
Dim ctl As Control
Dim some As String
Dim objExcel As Object
Dim objWord As Object
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application")
If objExcel Is Nothing Then
Set objExcel = CreateObject("Excel.Application")
End If
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
On Error GoTo 0
objExcel.Workbooks.Open ("File_Dir")
objExcel.Visible = False
objWord.Documents.Open ("File_Dir")
objWord.Visible = True
For Each ctl In Me.Controls
Select Case TypeName(ctl)
Case "CheckBox"
If ctl.Value = True Then
MsgBox ctl.Name
MsgBox objExcel.Names(ctl.Name).RefersToRange.Value
some = objExcel.Names(ctl.Name).RefersToRange.Value
End If
End Select
Next ctl
objExcel.Quit
Set objExcel = Nothing
MsgBox "complete"