【发布时间】:2015-02-27 01:44:53
【问题描述】:
我知道这个问题可能被问了 x1000 次,但在过去的 3 个小时里我一直在努力通过 excel vba 将 pptx 转换为 pdf(这是我的报告生成器所必需的,并且为了保持布局干净的广告tidy 我决定使用 PowerPoint,因为 word 总是把事情搞砸)。
这是我正在使用的代码:
Dim ppt As Object
On Error Resume Next
Set ppt = GetObject(, "PowerPoint.Application")
If ppt Is Nothing Then
Set ppt = CreateObject("PowerPoint.Application")
End If
On Error GoTo 0
Set WDReport = ppt.Presentations.Open("C:\Users\User1\Documents\Folder\Final Report Template.pptx")
WDReport.UpdateLinks
Dim FileName2 As String
FileName2 = "C:\Users\User1\Documents\Folder\Complete Report\" & Sheet14.Range("Q3").Text & " No " & Sheet14.Range("U21") & " Report" & Sheet17.Range("E10").Text & ".pdf"
WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF, ppFixedFormatIntentScreen
WDReport.Close
ppt.Quit
Set ppt = Nothing
Set WDReport = Nothing
但我一直在WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF, ppFixedFormatIntentScreen 行收到错误消息“13 类型不匹配”。我尝试用 ActivePresentation 替换 WDReport,但收到错误“429 ActiveX 组件无法创建对象”。
我已经包含了所有必要的库(Microsoft PowerPoint Object Library 15.0,与 MS Word 相同),但到目前为止没有任何效果。
更新:
只是为了澄清FileName2字符串,Ranges用于获取以下变量数据:
Range("Q3") is Name (e.g. Test Company)
Range("U21") is Number (e.g. 1234567891011)
Range("E10") is Date (e.g. Feb-15)
所以最终文件名将类似于 “Test Company No 1234567891011 Report Feb-15.pdf”。再一次,当我将 .docx 转换为 pdf 时,它运行良好
如果有人能帮助我解决这个问题,我将不胜感激。
【问题讨论】:
-
这可能是你的
FileName2=任务吗?特别是Sheet14.Range("U21")...你错过了.Text吗? -
嗨 Porcupine911。感谢您注意到我错过了
.Text,但不幸的是,这不是解决方案:(而且,奇怪的是,当我最初使用 MS 时,FileName2没有任何问题(即使没有.Text:D) Word而不是PPT。我不确定问题是否出在FileName2,因为我将那行改为FileName2 = "C:\Users\User1\Documents\Folder\Complete Report\Report.pdf",但仍然收到13和429错误... -
我尝试从 PowerPoint
Dim FileName2 As String: FileName2 = "C:\Users\User1\Documents\Folder\Complete Report\Report.pdf"; ActivePresentation.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF, ppFixedFormatIntentScreen运行这段代码,它工作得很好,所以我猜 Excel-PowerPoint 命令执行存在问题。虽然不知道如何修复它...
标签: excel pdf powerpoint vba