如何在 PowerPoint 中使用 VBA 打开嵌入的 OLE 对象 [英] How to use VBA in PowerPoint to open an embedded OLE object

查看:78
本文介绍了如何在 PowerPoint 中使用 VBA 打开嵌入的 OLE 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个简单的问题,但我花了几天时间寻找答案,但还没有.

I think this is a simple question, but I have spent days searching for an answer and nothing yet.

我在 PowerPoint 演示文稿(使用 PPT 2010 创建)中嵌入了一个 OLE 对象.我通过插入>对象>从文件创建>显示为图标方法嵌入了它(一个pdf文件),以便它在幻灯片上显示为一个小图标.

I have an OLE object embedded into a PowerPoint presentation (created using PPT 2010). I embedded it (a pdf file) through the insert>object>create from file>display as icon method, so that it displays as a little icon on a slide.

我的目标是通过单击形状打开它,其中形状位于与 pdf 所在的幻灯片不同的幻灯片上.pdf 在幻灯片 5 上,触发器形状在幻灯片 6 上.目标是在幻灯片查看期间打开它(并且必须通过 VBA 而不是出于其他原因的动画).

My goal is to open it on click of a shape, where the shape is on a different slide from the slide the pdf is on. The pdf is on slide 5, the trigger shape is on slide 6. The goal is to open it during slideshow viewing (and it must be done through VBA instead of animations for other reasons).

我认为以下方法可行:

Sub OpenMyDoc()
  ActivePresentation.Slides(5).Shapes("My Doc").OLEFormat.DoVerb(1)
End Sub

我已通过 insert>links 方法将该宏指定为点击操作".

I had assigned that macro as an on click "action" through the insert>links method.

我还尝试了以下变体,但都没有成功(当我点击触发形状时什么也没有发生):

I have also tried the following variations, with no luck (nothing happens at all when I click on the triggering shape):

ActivePresentation.SlideShowWindow.View.Slide.Shapes("My Doc").OLEFormat.DoVerb(1)

我也试过:

With SlideShowWindows(1).Presentation.Slides(5).Shapes("My Doc")
  OLEFormat.DoVerb(1)
End With

我也试过:

ActivePresentation.Slides.Item(5).Shapes.Item("My Doc").OLEFormat.DoVerb(1)

演示文稿中和同一张幻灯片上的其他宏(主要是消息框),所以我确定这不是权限或其他设置问题.我正在使用母版幻灯片,但似乎无法将问题追溯到那个.

Other macros (mostly message boxes) in the presentation, and on the same slide work, so I'm sure it's not a permissions or other setting issue. I am using master slides, but can't seem to trace the problem to that.

推荐答案

您可能在运行代码时看到了错误消息;错误消息解释了这个问题,虽然在某种程度上是 Microsoftcryptic 的方式.您只能从幻灯片或备注视图中激活 OLE 对象.

You probably saw an error message when you ran your code; the error message explains the problem, though in somewhat Microsoftcryptic fashion. You can only activate OLE objects from Slide or Notes view.

相反,您可以这样做:

ActivePresentation.Slides(1).Shapes(4).ActionSettings(1).Hyperlink.Follow

其中 Shapes(4) 超链接到您要启动的 PDF.

where Shapes(4) is hyperlinked to the PDF you want to launch.

但是由于超链接不是一种选择,并且由于您必须在幻灯片视图中才能激活嵌入的对象,因此这里可以使用:

But since hyperlinking isn't an option, and since you have to be in slide view to activate the embedded object, this works here:

' 激活演示窗口' 您可能需要确保它在正常视图中ActivePresentation.Windows(1).激活

' Activate the presentation window ' You might need to make sure it's in normal view ActivePresentation.Windows(1).Activate

' 启动 OLE 对象:ActivePresentation.Slides(1).Shapes(1).OLEFormat.DoVerb(1)

' Launch the OLE object: ActivePresentation.Slides(1).Shapes(1).OLEFormat.DoVerb (1)

' 并立即切换回幻灯片放映视图SlideShowWindows(1).激活

' And immediately switch back to slide show view SlideShowWindows(1).Activate

这篇关于如何在 PowerPoint 中使用 VBA 打开嵌入的 OLE 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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