使用Excel VBA来更改PowerPoint幻灯片尺寸 - 后期绑定 [英] Using Excel VBA to change PowerPoint Slide Size - Late Binding

查看:1979
本文介绍了使用Excel VBA来更改PowerPoint幻灯片尺寸 - 后期绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新十岁上下,以VBA和品牌新的StackOverflow,所以请原谅任何违反礼节的。我有一个项目,以创建使用Excel VBA的工具,使用户能够识别源Excel文件,然后在Excel中打印区域复制工作表的每个文件成幻灯片在一个新创建的PowerPoint presentation。我必须使用后期绑定,因为将全部使用Microsoft Office产品的版本相同,或者说,他们将启用参考PowerPoint对象库我不能假定该工具的用户。我已经成功地做​​到了这一切。在那里我得到挂了是,当我尝试设置幻灯片的大小 - 我一直在问的幻灯片是在4:如果需要使刀具工作在PowerPoint 2013提供3幻灯片大小(或类似的比例在老版本的PowerPoint - 我一直在试图ppSlideSizeLetterPaper)。这是投掷运行时错误438:对象不支持此属性或方法。如果任何人都可以提供建议,如何解决这个问题,我会很感激。

这里的code的相关片段:

 公共PowerPointApp作为对象
公众的TargetFile作为对象
...
子硕士()
设置PowerPointApp =的CreateObject(PowerPoint.Application)
Err.Clear
如果PowerPointApp是Nothing然后设置PowerPointApp =的CreateObject(等级:=PowerPoint.Application)
如果Err.Number的= 429然后
    MSGBOXPowerPoint无法找到。退出宏。
    退出小组
万一
设置的TargetFile = PowerPointApp。presentations.Add
    PowerPointApp.Visible = TRUE
    PowerPointApp.Activate
...< code从Excel中添加幻灯片和数据粘贴到幻灯片>
PowerPointApp.TargetFile.PageSetup.SlideSize = 2这正是引发错误。 2是ppSlideSizeLetterPaper的数字等效


解决方案

的TargetFile在这种情况下未定义 - 没有调用方法或属性的应用程序对象

正如你已经拥有该名称的对象,只是使用它。

  TargetFile.PageSetup.SlideSize = 2

I'm new-ish to VBA and brand new to StackOverflow, so please forgive any breaches of etiquette. 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. 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. 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). This is throwing "Run-time error '438': Object doesn't support this property or method". 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 

这篇关于使用Excel VBA来更改PowerPoint幻灯片尺寸 - 后期绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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