小工具的由來:某個周五下午筏餐,小默非常忙,還需要去見客戶牡拇。就在要去見客戶之前魁瞪,有7個非清潔版的word文件需要修改成清潔版再生成pdf,郵件發(fā)送給一個同事惠呼,雖然是小事导俘,緊急情況下還是會DT。因為見客戶比較重要罢杉,我選擇見完客戶回來再做趟畏。周末在家無聊,就想如果這種事情可以一鍵搞定多好滩租。
工具的作用
- 接受非清潔版中所有修訂赋秀;
- 刪除所有批注;
- 在當前文件夾下生成clean文件夾用以保存新生成的清潔word和pdf文件律想;
使用方法
初始準備階段
- 打開word文檔猎莲;
- 打開VBA編輯器;word打開VBA編輯器的方法
- 將以下代碼復(fù)制到VBA編輯器中技即;
- 添加快捷鍵著洼;添加按鈕教程
使用
- 使用方法1 打開需要批量處理文件夾下的一個word,點擊上述添加的快捷鍵而叼;
- 使用方法2 打開需要批量處理文件夾下的一個word身笤,打開宏運行【批量清潔版PDF文件生成工具】';
Sub 批量清潔版PDF文件生成工具BY陳默()
Dim path, file As String
Dim cmt As Comment
Dim doc As Document
Dim pdfname As String
Dim newdoc As String
Dim NewPath As String
Dim file_first As String
path = ActiveDocument.path & "\"
NewPath = path & "clean" & "\"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(NewPath) = False Then
MkDir NewPath '//創(chuàng)建文件夾
End If
file = Dir(path & "*.doc*")
file_first = file
Do While file <> ""
ChangeFileOpenDirectory path
Documents.Open FileName:=file, ConfirmConversions:= _
False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
For Each cmt In ActiveDocument.Comments
cmt.Delete
Next
ActiveDocument.AcceptAllRevisions
ActiveDocument.TrackRevisions = False
pdfname = Split(file, ".d")(0) & ".pdf"
newdoc = Split(file, ".d")(0) & "clean" & ".docx"
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
NewPath & pdfname, _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
ChangeFileOpenDirectory NewPath
ChangeFileOpenDirectory NewPath
ActiveDocument.SaveAs2 FileName:=newdoc, FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=15
ActiveDocument.Close
file = Dir
Loop
ChangeFileOpenDirectory path
Documents.Open FileName:=file_first, ConfirmConversions:= _
False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
End Sub