1
我試圖使用Application.DisplayAlerts = wdAlertsNone
或Application.DisplayAlerts = False
在我的劇本,以避免到有字彈出消息「被保存的文檔包含軌道變化繼續保存嗎?」隻字VBA腳本之前保存一個word文檔。但它不起作用。該消息仍然存在。保存Word文檔和DisplayAlerts
這裏我的腳本:
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
能否請你幫我解決這個問題?
預先感謝您的幫助
我無法複製您的錯誤(MS Word 2016)。錯誤源於這個過程:'CompareDocuments'。檢查比較結果,如果文檔很大,在關閉文檔之前可能需要更多時間。 –
即使文件很大,我的腳本仍在Word 2013下工作(同一文檔的兩個版本必須具有相同名稱的唯一方法。 – coeurdange57