繁体   English   中英

使用Excel VBA更改PowerPoint幻灯片大小 - 后期绑定

[英]Using Excel VBA to change PowerPoint Slide Size - Late Binding

我是VBA的新手,也是StackOverflow的新手,所以请原谅任何违反礼仪的行为。 我有一个使用Excel VBA创建工具的项目,该工具允许用户识别源Excel文件,然后将Excel文件中每个工作表的打印区域复制到新创建的PowerPoint演示文稿中的幻灯片中。 我必须使用后期绑定,因为我不能假设该工具的用户都将使用相同版本的Microsoft Office产品,或者他们将启用对PowerPoint对象库的引用。 我设法做到了这一切。 当我试图设置幻灯片的大小时,我被挂断的地方 - 我被要求幻灯片放在PowerPoint 2013中可用的4:3幻灯片大小(如果需要,可以使工具正常工作在旧版本的PowerPoint中 - 我一直在尝试使用ppSlideSizeLetterPaper)。 这是抛出“运行时错误'438':对象不支持此属性或方法”。 如果有人能提出如何解决这个问题的建议,我将不胜感激。

以下是代码的相关摘要:

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

目标文件在该上下文中未定义 - 在应用程序对象上没有调用该方法或属性。

因为你已经有了这个名字的对象,所以就这样使用它。

TargetFile.PageSetup.SlideSize = 2 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM