我在文件夹中有一堆word文档。有些是.docx文件,有些是.doc文件。我的代码适用于.docx文件,但是每次文件为.doc文件时,都会提示我进行保存。我正在使用超过5k的.doc文件,所以有没有一种方法可以保存而不提示我。谢谢
Sub WordDocScrubber()
Dim directory As String, fileName As String, i As Variant, dc As Document
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim security As MsoAutomationSecurity
security = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityForceDisable
directory = "C:\Users\bayli\Desktop\Files for Testing\"
fileName = Dir(directory & "*.do??")
i = 0
Do While fileName <> vbNullString
On Error Resume Next
Set dc = Documents.Open(directory & fileName)
If Err.Number = 0 And Not dc Is Nothing Then
On Error GoTo 0
dc.RemoveDocumentInformation (wdRDIAll)
dc.Close savechanges:=True,originalformat:=wdOriginalDocumentFormat
'dc.Close savechanges:=True, originalformat:=wdWordDocument
i = i + 1
Application.StatusBar = "Files Completed: " & i
fileName = Dir()
Else
Err.Clear
On Error GoTo 0
'Handle
End If
Loop
Application.AutomationSecurity = security
Application.StatusBar = False
Application.ScreenUpdating = True
Application.DisplayAlerts = True
MsgBox "Complete"
End Sub
答案 0 :(得分:0)
请尝试改为dc.close:
dc.Save
dc.Saved = True 'extra code, maybe not necessary
dc.Close wdDoNotSaveChanges