1
votes

I am processing word documents in batch in an excel vba script.

I open the docs using the following commands:

Set objDoc = Documents.Open(FileName:=sUri, ReadOnly:=True, ConfirmConversions:=False, RecentFiles:=False)

The problem I have is that when opening some docs, MSWord throws a message box asking if the user wants to merge changes. How do I get rid of this message box so that my script can run without human supervision?

EDIT 1 following @Pᴇʜ advice I updated my code to this:

Dim appWD As Word.Application
Dim objDoc As Document

Set appWD = CreateObject("Word.Application")
appWD.DisplayAlerts = False


Set objDoc = appWD.Documents.Open(FileName:=sUri, _
                            ReadOnly:=True, _
                            ConfirmConversions:=False, _
                            AddToRecentFiles:=False)

I have another case with a messagebox called "Show repairs" that still shows despite the DisplayAlerts = False. Is my code wrong or is it another option I can disable?

EDIT 2 - OpenNoRepairDialog The Documents object has a method OpenNoRepairDialog which prevents the opening of the Show Repairs message box.

I am going to test a bit more to make sure the question topic is solved with DisplayAlerts = False.

1
Use Application.DisplayAlerts = False before opening the file and set it True afterwards. You might need to replace the Application with the variable name of your Word application.Pᴇʜ

1 Answers

0
votes

If you have a look at the documentation of the Documents.Open method you see that there is a OpenAndRepair parameter.

If you set it to False the open and repair dialog should disappear.