Communicating between Excel and Word

adeeshc

New Member
Joined
Dec 20, 2011
Messages
24
I am looking to write a procedure in Excel which opens a Word document.
Challenge is that the Word document has an AutoOpen procedure resulting in the word document opening with a vbYesNo MsgBox.
I want to select Yes all the time. And then continue with the AutoOpen word procedure.

Again I cannot change the Word document code as this requires the user to give the desired input when opened independently.

So I want this input to be passed from my initial Excel procedure.


Hope someone could help me with this here. I am too tired after trying various methods throughout the day without success :(
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello,

Why don't you post your current VBA code ...
 
Upvote 0
Hello,

Why don't you post your current VBA code ...

wordapp.documents.Open (ActiveWorkbook.Path + "" + PN + "_Report.docm")
wordapp.Visible = True

wordapp.documents.Save
wordapp.documents.Close


The above is what I have ....this opens the word document, runs its autoopen procedure, and prompts for a VBYesNo. I need to skip this step and automatically give the Yes and proceed.
 
Upvote 0
One way is to disable execution of the AutoOpen macro in Word (wordapp.WordBasic.DisableAutoMacros 1) and use your Excel automation to do whatever aspect of the [disabled] Word AutoOpen macro you want to perform.

Alternatively, you'll need to modify the Word code to enclose the MsgBox prompt in a If test that can be used to bypass it when the document is opened programmatically. In such a scenario, the Word code might look like:
Code:
Sub AutoOpen()
  Call Main(False)
End Sub

Sub Main(bAutomation As Boolean)
If bAutomation = True Then
  Rslt = vbYes
Else
  Rslt = MsgBox("Some Prompt", vbYesNo)
End If
'The rest of the Word code from the existing AutoOpen macro goes here.
End Sub
where bAutomation is a Boolean you'll be able to pass to Word from your Excel code. And, in Excel, you'd use something like:
Code:
With wordapp
  .WordBasic.DisableAutoMacros 1
  .Visible = True
  Set wdDoc = .Documents.Open(FileName:=ActiveWorkbook.Path + "\" + PN + "_Report.docm", _
    AddToRecentFiles:=False, Visible:=False)
  .Run Main, True
  With wdDoc
    'Do whatever you need Excel to do with the document
    .Close True
  End With
End With
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,824
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top