I have a VBA Word macro that opens a Word doc, then opens an Excel file, selects a cell reference and finally displays a message using Msgbox. After the Excel file has been opened I am having trouble finding the code to make Word visible so that the user can view the Msgbox message without having to using the task bar to switch from Excel to Word. I tried oWord.Visible = True
but VBA gives me an error.
Any hints are appreciated.
See the code below:
Sub Module_Test()
Dim oExcel As Object
Dim oWord_Doc as object
Dim wb_open as workbook
Set oExcel = New Excel.Application
str_Excel_Filename = "C:\Test\Excel_Template.xlsx"
Documents.Open ("C:\Test\Doc_to_process.docx")
Set oWord_Doc = activedocument
oExcel.Visible = True
oExcel.ScreenUpdating = True
oExcel.Workbooks.Open str_Excel_Filename
Set wb_open = activeworkbook
wb_open.ActiveSheet.range("a6").Select
' At this point Excel is visible. But the Msgbox statement below is not visible except when one switches to Word using the task bar. What statement do I put here to make Word visible?
Msgbox "Here is a message that should be visible when viewing the window containing the Doc_to_process.docx"
End Sub
oWord_Doc.Activate
below thewb_open
line – Jchang43AppActivate "Microsoft Word"
orAppActivate Application.Caption
– Tim WilliamsoWord_Doc.Activate
compiles just fine but doesn't switch the active application to Word (but it does if you put a stop on the line in the VBA editor).AppActivate "Microsoft Word"
andAppActivate Application.Caption
both results in an execution error of Invalid procedure call or argument. Thanks Brotato and @tim-williams for your suggestions. – Kaiser Otto