利用vbs将word、excel、ppt转换成pdf
代码如下:
Excel:
path = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
Set objArgs = WScript. Arguments
Set oExcel = CreateObject("Excel.Application")
Set oWb = oExcel.Workbooks.Open(path & "\" & "tmp.xlsx")
oWb.ExportAsFixedFormat xlTypePDF, path & "\" & "tmp.pdf", 1,1,1,1
oExcel.Visible = False
oExcel.quit
Set oWb = Nothing
Word:
path = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
Set word = CreateObject("Word.application")
Set docx = word.Documents.Open(path & "\" & "tmp.doc")
docx.SaveAs path & "\" & "tmp.pdf",17
docx.close(doNotSaveChanges)
word.Quit
set docx = nothing
Set word = nothing
PPT:
path = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
Set ppt = CreateObject("PowerPoint.application")
Set pptfile = ppt.Presentations.Open(path & "\" & "tmp.ppt",false,false,false)
pptfile.Saveas path & "\" & "tmp.pdf",32,false
ppt.Quit
Set pptfile= nothing
path = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path表示获得当前文件所在的路劲
tmp.ppt为原始文件
tmp.pdf为转换过的pdf文件
主要是参考这位前辈的附上地址https://blog.csdn.net/dqmtqqq/article/details/54848432