【问题标题】:Excel/PowerPoint VBA and late bindingExcel/PowerPoint VBA 和后期绑定
【发布时间】:2017-11-22 04:22:18
【问题描述】:

我一直在构建一个工具来从 Excel 工作簿中的数据生成 PowerPoint 幻灯片。我在工作的电脑和家里的电脑之间来回移动。工作计算机有 Excel 2013,而家用计算机有 2016。这通常不是问题......当我从家用计算机移动到工作计算机时,我只需将引用从 v16 对象库更改为 v15 对象图书馆。

本周早些时候,虽然我遇到了无法解决的错误...详细here 解决该问题的建议之一是切换到后期绑定,因此我不需要参考。这是一个非常简单的切换,但它导致生成的 ppt 幻灯片中出现错误......

在原始(早期绑定)版本中,我进行了如下设置

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim PPLayout As CustomLayout
Dim PPshape As Variant
Dim tBox As PowerPoint.Shape

然后

Set PPApp = New PowerPoint.Application
Set PPPres = PPApp.Presentations.Open(fileName, msoTrue, , msoFalse)

然后部分幻灯片是用

构建的
wsGenerator.Activate
wsGenerator.Range("B32:L37").Select
Selection.Copy
With PPSlide.Shapes.PasteSpecial(ppPasteMetafilePicture)
     .Top = 450
     .Left = 50
     .Height = 100
     .Width = 325
End With

生成的幻灯片的一部分如下所示

底部的表格是上面代码粘贴的部分。

当我更改为后期绑定时,我只需进行这些更改

'Dim PPApp As PowerPoint.Application
Dim PPApp As Object

'Dim PPPres As PowerPoint.Presentation
Dim PPPres As Object

'Dim PPSlide As PowerPoint.Slide
Dim PPSlide As Object

'Dim PPLayout As CustomLayout
Dim PPLayout As Object

'Dim tBox As PowerPoint.Shape
Dim tBox As Object

Dim PPshape As Variant

然后

'Set PPApp = New PowerPoint.Application
Set PPApp = CreateObject("PowerPoint.Application")

其他一切都保持不变。生成的图表现在看起来像这样

请注意,它现在延伸到幻灯片的底部。

你有什么想法吗?

【问题讨论】:

  • 为什么不试试 www.pptxbuilder.com,它的功能与您正在做的类似......

标签: vba excel powerpoint


【解决方案1】:

您似乎已将声明更改为后期绑定,但您可能仍在使用一些 PowerPoint 常量(例如 ppPasteMetafilePicture),它们将不再解析为它们的早期绑定值,而是默认为0

您需要为ppPasteMetafilePicture 定义一个局部常量,以便该值可用。

顺便说一句,您应该始终使用Option Explicit,然后 VBE 会自动发现未声明常量的用法。

【讨论】:

  • 呃!当然!谢谢你……我也很自责,因为我通常总是使用显式选项,但这次却以某种方式失败了。
猜你喜欢
  • 2019-03-09
  • 1970-01-01
  • 1970-01-01
  • 2011-08-23
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-23
相关资源
最近更新 更多