我是新十岁上下对VBA和品牌新的StackOverflow,所以请原谅任何违反礼仪的。 我有一个项目,以创建使用Excel VBA的工具,使用户能够识别源Excel文件,然后在Excel中的打印区域复制工作表的每个文件到幻灯片中新创建的PowerPoint演示文稿。 我必须使用后期绑定,因为将全部使用Microsoft Office产品的版本相同,或者说,他们将启用了参考PowerPoint对象库我不能假定该工具的用户。 我已经成功地做到了这一切。 当我收到挂了是,当我尝试设置幻灯片的大小 - 我一直在问的幻灯片是在4:如果需要使刀具工作在PowerPoint 2013提供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