PowerPoint 2007 單檔另存 PDF 容易,但百檔批量轉換無內建功能。利用 VBScript 呼叫 PowerPoint COM 物件模型 `SaveAs` 方法 (檔案類型常數 32 = PDF),整合至檔案總管右鍵選單,實現「有 PPT 的地方就有 PDF」的一鍵批量轉換。
Office 2007 安裝「另存為 PDF 增益集」 (SaveAsPDFandXPS.exe) 後,PowerPoint 物件模型新增 `ppSaveAsPDF = 32` 常數。VBScript 建立 PowerPoint.Application 實例,批次開啟 .ppt/.pptx → `SaveAs 新路徑, 32` → 關閉 → 退出。
記事本建立 pdf.vbs (儲存於固定路徑,如 C:\Scripts\pdf.vbs):
' PDF.VBS - 批量 PPT 轉 PDF
On Error Resume Next
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True ' 可見模式便於觀察/除錯
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then WScript.Quit
For i = 0 To objArgs.Count - 1
strFile = objArgs(i)
If LCase(Right(strFile, 4)) = ".ppt" Or LCase(Right(strFile, 5)) = ".pptx" Then
Set objPres = objPPT.Presentations.Open(strFile, , , False)
strNew = Left(strFile, InStrRev(strFile, ".")) & "pdf"
objPres.SaveAs strNew, 32 ' 32 = ppSaveAsPDF
objPres.Close
End If
Next
objPPT.Quit
PPT2PDFC:\Windows\System32\wscript.exe "C:\Scripts\pdf.vbs" "%1"%1 為傳入的檔案完整路徑,雙引號處理路徑空格)。此方案解決了 PowerPoint 2007 缺乏批量轉 PDF 的痛點,同樣適用於 Word/Excel (對應常數 `wdSaveFormatPDF = 17` / `xlTypePDF = 0`)。