禁止 Word 保存有关跟踪更改的提示

问题描述 投票:0回答:2

在论坛用户的帮助下,我能够完美地执行以下代码。 然而,当我想保存并关闭word程序时,却提示如下一行:

正在保存的文档包含跟踪的更改。继续保存吗?

有没有办法在使用VBA保存word文档时抑制所有提示和警告?

我的工作代码:

Sub DocSearchandReplace()

Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("P:\test.doc")

With wdDoc.Content.Find
    .ClearFormatting
    .Text = "[0-9]{2}.[0-9]{2}.[0-9]{4}"  
    .MatchWildcards = True 
    .Replacement.ClearFormatting
    .Replacement.Text = ThisWorkbook.Worksheets("sheet1").Range("A1").Text 
    .Execute Replace:=2, Forward:=True, Wrap:=1
End With

wdDoc.Save                    'it prompts and asks me whether continue to save
wdApp.ActiveDocument.PrintOut 'here again the same prompt when executing this line.
wdApp.Quit


Set wdApp = Nothing: Set wdDoc = Nothing

End Sub
excel vba ms-word
2个回答
0
投票

wdApp.Options.WarnBeforeSavingPrintingSendingMarkup = false


0
投票

如果您想禁用保存提示,您可以这样做:

  wdApp.ActiveDocument.Saved = True   
  wdApp.ActiveDocument.SaveAs (path & newFile)

记住保存提示不能仅通过此代码禁用:

Application.DisplayAlerts=false

您也可以使用此 VBA 代码:

 Documents.Save NoPrompt:=True, _ 
 OriginalFormat:=wdOriginalDocumentFormat

想要将更改保存到....

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