用于保存word文档和DisplayAlerts的Word vba脚本

问题描述 投票:1回答:1

我正在尝试在我的脚本中使用Application.DisplayAlerts = wdAlertsNoneApplication.DisplayAlerts = False以避免出现Word弹出消息“正在保存的文档包含跟踪更改继续保存?”就在保存word文档之前。但它不起作用。该消息仍然存在。

我的脚本在这里:

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

你能帮我解决一下这个问题吗?

预先感谢您的帮助

word-vba
1个回答
0
投票

显然,这取决于办公室的版本,2013年有必要转到应用程序的信任中心区域(文件>选项>信任中心>信任中心设置>隐私选项),并取消选中“打印,保存或发送前保暖”选项包含跟踪的更改或注释的文件“。执行该操作后,文件将与Word的任何消息一起保存

© www.soinside.com 2019 - 2024. All rights reserved.