【发布时间】:2015-04-23 20:02:17
【问题描述】:
我是 VBA 的新手,也是 StackOverflow 的新手,所以请原谅任何违反礼仪的行为。我有一个使用 Excel VBA 创建工具的项目,该工具将允许用户识别源 Excel 文件,然后将 Excel 文件中每个工作表的打印区域复制到新创建的 PowerPoint 演示文稿中的幻灯片中。我必须使用后期绑定,因为我不能假设该工具的用户都将使用相同版本的 Microsoft Office 产品,或者他们将启用对 PowerPoint 对象库的引用。我已经设法做到了这一切。当我尝试设置幻灯片的大小时,我被挂断了 - 有人要求我将幻灯片的大小设为 PowerPoint 2013 中可用的 4:3 幻灯片大小(或者如果需要使该工具正常工作,则为类似的比例在旧版本的 PowerPoint 中 - 我一直在尝试 ppSlideSizeLetterPaper)。这是抛出“运行时错误'438':对象不支持此属性或方法”。如果有人能就如何解决这个问题提供建议,我将不胜感激。
下面是相关的sn-ps代码:
Public PowerPointApp As Object
Public TargetFile As Object
…
Sub Master()
Set PowerPointApp = CreateObject("PowerPoint.Application")
Err.Clear
If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
If Err.Number = 429 Then
MsgBox "PowerPoint could not be found. Exiting macro."
Exit Sub
End If
Set TargetFile = PowerPointApp.Presentations.Add
PowerPointApp.Visible = True
PowerPointApp.Activate
…<code to add slides and paste data from Excel into the slides>
PowerPointApp.TargetFile.PageSetup.SlideSize = 2 ‘this is where the error is thrown. 2 is the numeric equivalent of ppSlideSizeLetterPaper
【问题讨论】:
标签: excel vba binding powerpoint