PDA

View Full Version : DisplayAlerts is not working in a Word vba script for saving a word documement



coeurdange57
12-18-2017, 03:19 AM
Hi,

I'm trying to use
Application.DisplayAlerts = wdAlertsNone or
Application.DisplayAlerts = False in my script for avoiding to a have the Word popup message "The document being saved contains track changes Continue with save?" just before to save a word document. But it's not working. The message is still present.

Here my script:


Private Sub CreateReportButton_Click()
Dim objDocA As Word.Document
Dim objDocB As Word.Document
Dim objDocC As Word.Document

Dim objFSO As Scripting.FileSystemObject
Dim objFolderA As Scripting.Folder
Dim objFolderB As Scripting.Folder
Dim objFolderC As Scripting.Folder

Dim colFilesA As Scripting.Files
Dim objFileA As Scripting.File

Dim i As Integer
Dim j As Integer

Set objFSO = New FileSystemObject
Set objFolderA = objFSO.GetFolder(ChooseFolder("Choose the folder with the original documents", ThisDocument.Path))
Set objFolderB = objFSO.GetFolder(ChooseFolder("Choose the folder with revised documents", ThisDocument.Path))
Set objFolderC = objFSO.GetFolder(ChooseFolder("Choose the folder for the comparisons documents", ThisDocument.Path))

Set colFilesA = objFolderA.Files

For Each objFileA In colFilesA
If objFileA.Name Like "*.docx" Then
Set objDocA = Documents.Open(objFolderA.Path & "\" & objFileA.Name)
Set objDocB = Documents.Open(objFolderB.Path & "\" & objFileA.Name)
Set objDocC = Application.CompareDocuments( _
OriginalDocument:=objDocA, _
RevisedDocument:=objDocB, _
Destination:=wdCompareDestinationNew)
objDocA.Close
objDocB.Close
On Error Resume Next
Kill objFolderC.Path & "\" & objFileA.Name
On Error GoTo 0

'Turn off DisplayAlerts
Application.DisplayAlerts = wdAlertsNone

objDocC.SaveAs FileName:=objFolderC.Path & "\" & objFileA.Name
objDocC.Close SaveChanges:=False
End If
Next objFileA

End Sub

Could you please help me to solve the problem?
Thank you in advance for your help

coeurdange57
12-18-2017, 06:56 AM
Apparently it depends on the version of office, In 2013 it's necessary to go to the Trust Center area of the application (File > Options > Trust Center > Trust Center Settings > Privacy Options) and uncheck the option "Warm before printing, saving or sending a file that contains tracked changes or comments". After doing that files are saved with any message of Word :content:

macropod
12-18-2017, 02:02 PM
This is a continuation of your CROSS_POSTED discussion in: http://www.vbaexpress.com/forum/showthread.php?61577-Process-indicator-in-a-script. Kindly don't create duplicate threads for the same discussion. Thread closed. You may continue the discussion in the original thread.