Excel宏将pptx保存为pdf;代码错误 [英] Excel macro to save pptx as pdf; error with code

查看:116
本文介绍了Excel宏将pptx保存为pdf;代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题可能被问过1000次,但过去3个小时我一直在努力通过excel vba将pptx转换为pdf(这是我的报告生成器所必需的,并且为了保持布局整洁的广告整洁,我决定使用PowerPoint,因为单词经常使事情变得混乱.

I know that this question probably was asked x1000 times, but I've been struggling for the past 3 hours to covert pptx to pdf via excel vba (this is required for my report generator, and in order to keep layout clean ad tidy I've decided to use PowerPoint, because word constantly mess things up).

这是我正在使用的代码:

Here's the code I'm using:

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 Type Mismatch".我试图用ActivePresentation替换WDReport,但是收到并显示错误"429 ActiveX Component Cant Create Object".

But I keep receiveing an error message "13 Type Mismatch" on the line WDReport.ExportAsFixedFormat FileName2, ppFixedFormatTypePDF, ppFixedFormatIntentScreen. I've tried to replace WDReport with ActivePresentation, but received and error "429 ActiveX Component Cant Create Object".

我已经包含了所有必需的库(Microsoft PowerPoint对象库15.0,与MS Word相同),但到目前为止没有效果.

All I've included all necessary libraries (Microsoft PowerPoint Object Library 15.0, same with MS Word), but no effect so far.

UPD:

仅是为了阐明FileName2字符串,Ranges用于获取以下变量数据:

Just to clarify the FileName2 string, Ranges are used to get the following variable data:

Range("Q3") is Name (e.g. Test Company)
Range("U21") is Number (e.g. 1234567891011)
Range("E10") is Date (e.g. Feb-15)

因此,最终文件名将类似于测试公司编号1234567891011报告Feb-15.pdf" .再次,当我将.docx转换为pdf时,它工作正常

So the final file name would be like "Test Company No 1234567891011 Report Feb-15.pdf". Once again, it worked fine when I was converting .docx to pdf

如果有人可以帮助我解决这个问题,我将非常感激.

I'd really appreciate if anyone could help me with this issue.

推荐答案

我能够重现您的错误.以下解决方案为我工作.确保已启用对Microsoft Powerpoint对象库的引用.

I was able to reproduce your errors. The following solution worked for me. Make sure you have enabled your reference to the Microsoft Powerpoint Object Library.

WDReport.SaveAs FileName2, ppSaveAsPDF

这篇关于Excel宏将pptx保存为pdf;代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆