原文地址: https://www.cnblogs.com/Mr-nie/p/8029085.html
複製下面的代碼,保存的記事本,另存爲vbs文件;然後把這個vbs文件放到你要轉PDF的文件夾裏(doc和docx文件都可以)。雙擊運行,等待 Word文件已全部軒換爲PDF格式! 的對話框 代表已經全部轉化完成。
On Error Resume Next
Const wdExportFormatPDF = 17
Set oWord = WScript.CreateObject("Word.Application")
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set fds=fso.GetFolder(".")
Set ffs=fds.Files
wscript.echo "Word文件正在轉換中,請勿關閉當前窗口..."
For Each ff In ffs
If (LCase(Right(ff.Name,4))=".doc" Or LCase(Right(ff.Name,4))="docx" ) And Left(ff.Name,1)<>"~" Then
Set oDoc=oWord.Documents.Open(ff.Path)
odoc.ExportAsFixedFormat Left(ff.Path,InStrRev(ff.Path,"."))&"pdf",wdExportFormatPDF
If Err.Number Then
MsgBox Err.Description
End If
End If
Next
odoc.Close
oword.Quit
Set oDoc=Nothing
Set oWord =Nothing
wscript.echo "Word文件已全部轉換爲PDF格式!"
MsgBox "Word文件已全部轉換爲PDF格式!"