|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 cuanju 于 2019-11-24 12:41 编辑
分享一个宏,运行宏可将单个word文件转换为PDF,并保存到桌面。(Windows7桌面默认路径是C:\Users\Administrator\Desktop,而Windows10桌面默认路径是C:\Users\Admin\Desktop,此代码已自动判断)
==========================
Sub word将单个文件转换为PDF()
Set oD = ActiveDocument
Dim sPath As String
Set xlApp = CreateObject("excel.Application")
If xlApp.OperatingSystem Like "*6.01*" Then
sPath = "C:\Users\Administrator\Desktop\"
Else
sPath = "C:\Users\Admin\Desktop\"
End If
If Split(oD.Name, ".")(0) Like "*文档[0-9]*" Then
oD.ExportAsFixedFormat OutputFileName:=(sPath & Format(Now(), "yymmdd_hhmmss") & Split(oD.Name, ".")(0) & ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=1, To:=oD.Range.Information(wdNumberOfPagesInDocument), _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True
Else
oD.ExportAsFixedFormat OutputFileName:=(sPath & Left(oD.Name, InStrRev(oD.Name, ".") - 1) & ".pdf"), _
ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportFromTo, From:=1, To:=oD.Range.Information(wdNumberOfPagesInDocument), _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True
End If
xlApp.Quit
Set xlApp = Nothing
End Sub |
评分
-
1
查看全部评分
-
|