欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Word文件转PDF

程序员文章站 2024-03-17 15:05:04
...
Sub doc2pdf()
'
' doc2pdf 宏
'
'
Dim file As String
ChangeFileOpenDirectory "F:\我的工作文档\Word文件\"   '文件夹位置

file = Dir("*.docx")
Do Until file = ""
    On Error GoTo MyErr  '跳过
    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 wdDoNotSaveChanges
    
MyErr:     '发生异常跳过中间程序至该行语句

file = Dir
Loop

End Sub

 

相关标签: Word office VBA