Document_Open () fails when I open the document by Macro vba in Excel

0

I have an excel with the following vba code:

Dim objWord
Dim objDoc
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("Ruta") 'Ruta verificada

And I have a word document with this vba code:

Private Sub Document_Open()
Dialogs(wdDialogFilePrint).Show
End Sub

If I open the word "by hand" everything works correctly, but if I execute the macro in the excel, after 40-50 seconds this message appears:

And keep trying ... until I force the closing of the excel.

Any suggestions?

    
asked by David_helo 22.08.2018 в 15:42
source

1 answer

0

Ok, the code that you're running waits for a response from the user, because it opens the printer options dialog box and so on.

To me your code gives me the same error, and I have fixed it by making the Word Application Object visible:

Dim objWord
Dim objDoc
Set objWord = CreateObject("Word.Application")

objWord.Visible = True 'lo volvemos visible

Set objDoc = objWord.Documents.Open("Ruta") 'Ruta verificada

In this way, the code waits for the user to close the dialog box. When it is closed, the Excel code will continue to run.

    
answered by 25.08.2018 / 02:36
source