简体   繁体   English

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

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

I'm new-ish to VBA and brand new to StackOverflow, so please forgive any breaches of etiquette. 我是VBA的新手,也是StackOverflow的新手,所以请原谅任何违反礼仪的行为。 I have a project to create a tool using Excel VBA that will allow the user to identify a source Excel file and then copy the print area of every worksheet in the Excel file into a slide in a newly created PowerPoint presentation. 我有一个使用Excel VBA创建工具的项目,该工具允许用户识别源Excel文件,然后将Excel文件中每个工作表的打印区域复制到新创建的PowerPoint演示文稿中的幻灯片中。 I have to use late binding because I can't assume the users of the tool will all be using the same versions of the Microsoft Office products, or that they will have enabled the reference to the PowerPoint Object Library. 我必须使用后期绑定,因为我不能假设该工具的用户都将使用相同版本的Microsoft Office产品,或者他们将启用对PowerPoint对象库的引用。 I have managed to do all of this. 我设法做到了这一切。 Where I am getting hung up is when I try to set the size of the slides - I have been asked for the slides to be in the 4:3 slide size available in PowerPoint 2013 (or a similar ratio if needed to make the tool work in older versions of PowerPoint - I have been trying for ppSlideSizeLetterPaper). 当我试图设置幻灯片的大小时,我被挂断的地方 - 我被要求幻灯片放在PowerPoint 2013中可用的4:3幻灯片大小(如果需要,可以使工具正常工作在旧版本的PowerPoint中 - 我一直在尝试使用ppSlideSizeLetterPaper)。 This is throwing "Run-time error '438': Object doesn't support this property or method". 这是抛出“运行时错误'438':对象不支持此属性或方法”。 If anyone could offer suggestions as to how to get around this, i'd be grateful. 如果有人能提出如何解决这个问题的建议,我将不胜感激。

Here's the relevant snippets of the code: 以下是代码的相关摘要:

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 is undefined in that context - there is no method or property called that on the application object. 目标文件在该上下文中未定义 - 在应用程序对象上没有调用该方法或属性。

As you've already have an object of that name, just use that. 因为你已经有了这个名字的对象,所以就这样使用它。

TargetFile.PageSetup.SlideSize = 2 

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

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