How to use VBA in PowerPoint to open an embedded OLE object

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

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.

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).

I thought the following would work:

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

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)

I also tried:

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

I also tried:

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.


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.

Instead, you can do this:

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

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

[EDIT]

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

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

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

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

链接地址: http://www.djcxy.com/p/45682.html

上一篇: 编辑嵌入式Excel OLE对象中表的列名称

下一篇: 如何在PowerPoint中使用VBA打开嵌入的OLE对象