Loading

vba word 批量转换为pdf

1.第一个

Option Explicit
Sub docx2pdf()
Dim sEveryFile As String
Dim sSourcePath As String
Dim sNewSavePath As String
Dim CurDoc As Object
sSourcePath = "C:\akita\test"
sEveryFile = Dir(sSourcePath & "*.doc")
Do While sEveryFile <> ""
Set CurDoc = Documents.Open(sSourcePath & sEveryFile, , , , , , , , , , , msoFalse)
sNewSavePath = VBA.Strings.Replace(sSourcePath & "pdf" & sEveryFile, ".docx", ".pdf")
sNewSavePath = VBA.Strings.Replace(sNewSavePath, ".doc", ".pdf")
CurDoc.SaveAs2 sNewSavePath, wdFormatPDF
CurDoc.Close SaveChanges:=False
sEveryFile = Dir
Loop
Set CurDoc = Nothing
End Sub

2、第二个

Sub doc2pdf()
'
' doc2pdf 宏
'
'
Dim file As String
ChangeFileOpenDirectory "C:\Users\jskzls\Desktop\测试" '文件夹位置

file = Dir("*.doc")
Do Until file = ""
Documents.Open FileName:=file
FileName = ActiveDocument.Name
BaseName = Left(FileName, InStrRev(FileName, ".") - 1)
ActiveDocument.ExportAsFixedFormat OutputFileName:= _
BaseName & ".pdf", 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

file = Dir
Loop

End Sub
`

posted @ 2023-12-14 23:07  Lust4Life  阅读(614)  评论(0)    收藏  举报