近日手头有些word文档要转换成pdf,正好word2010及以上版本是可以直接另存为pdf格式,排版毫无问题速度也块,问题就在于人比较懒,文件一多就想偷懒。
上网搜索word批量转换成pdf,各种虚拟打印机、插件和专用软件,不光步骤繁琐,而且有些转换成纯图片格式的pdf,质量堪忧。于是考虑word的宏命令功能。
宏命令基于VBA脚本,由于上世纪宏病毒肆掠,word本身是不显示宏选项卡的,需要在 开始–选项–自定义功能区中添加(某些版本可能在视图选项卡中默认存在)
然后录制宏,其过程为保存一个文件为pdf,然后停止录制。之后点击查看宏–编辑,打开VBA编辑器,将已存在的代码编辑最后如下:
Sub doc2pdf()
'
' doc2pdf 宏
'
'
Dim file As String
ChangeFileOpenDirectory "C:\Users\cheng\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
心飞扬路逍遥2017 年 12 月 13 日下午 5:01
超赞!!!