Word转PDF的VBA脚本


将以下内容复制粘贴在一个txt中,修改txt后缀为“.vbs”

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

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

odoc.Close wdDoNotSaveChanges

End If

Next

   

oword.Quit

Set oDoc=Nothing

Set oWord =Nothing

MsgBox "Word文件已全部转换为PDF格式!"


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM