本文主要是介绍【MOMO_Tips】批量将word转换为PDF格式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
批量将word转换为PDF格式
1.打开文件–>选项–>自定义功能区–>开发工具–>确定
2.点开开发工具,选择第一个visual basic
3.进入页面后找到插入–>模块,就可以看到这样的画面之后将下列vba代码复制粘贴到模块中
Sub ConvertWordsToPdfs()
'Updated by Extendoffice 20181123Dim xIndex As StringDim xDlg As FileDialogDim xFolder As VariantDim xNewName As StringDim xFileName As StringSet xDlg = Application.FileDialog(msoFileDialogFolderPicker)If xDlg.Show <> -1 Then Exit SubxFolder = xDlg.SelectedItems(1) + "\"xFileName = Dir(xFolder & "*.*", vbNormal)While xFileName <> ""If ((Right(xFileName, 4)) <> ".doc" Or Right(xFileName, 4) <> ".docx") ThenxIndex = InStr(xFileName, ".") + 1xNewName = Replace(xFileName, Mid(xFileName, xIndex), "pdf")Documents.Open FileName:=xFolder & xFileName, _ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _PasswordDocument:="", PasswordTemplate:="", Revert:=False, _WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _wdOpenFormatAuto, XMLTransform:=""ActiveDocument.ExportAsFixedFormat OutputFileName:=xFolder & xNewName, _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:=FalseActiveDocument.CloseEnd IfxFileName = Dir()Wend
End Sub
4.按 F5 键或点击上面的运行来运行代码,会弹出浏览对话框,请选择包含要转换为pdf文件的Word文档的文件夹,然后单击OK按钮。
这篇关于【MOMO_Tips】批量将word转换为PDF格式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!