Last active
April 27, 2023 03:05
-
-
Save michaelHL/3e8f78052487b77b06e9049f56ce71f9 to your computer and use it in GitHub Desktop.
vba - 批量word转pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub ConvertWordsToPdfs() | |
Dim directory As String | |
directory = "PATH\TO\DESIRED\DIR" ' The starting directory | |
Dim fso, newFile, folder, files | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set folder = fso.GetFolder(directory) | |
Set files = folder.files | |
For Each file In files | |
Dim newName As String | |
newName = Replace(file.Path, ".doc", ".pdf") | |
Documents.Open fileName:=file.Path, _ | |
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _ | |
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _ | |
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _ | |
wdOpenFormatAuto, XMLTransform:="" | |
ActiveDocument.ExportAsFixedFormat OutputFileName:=newName, _ | |
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _ | |
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _ | |
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _ | |
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _ | |
BitmapMissingFonts:=True, UseISO19005_1:=False | |
ActiveDocument.Close | |
Next | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment