J
Josh Sale
Hi. This is my first attempt to write a PowerPoint macro though I've written lots of Excel macros.
I have a few questions:
First, I'm trying to write a simple macro that will loop through all of the slides in the open PowerPoint presentation and identify each embedded Excel worksheet and activate it (the reason for this isn't important but the worksheet is connected to a database and I want to get fresh data). My macro looks like this:
Sub UpdateExcelShapes()
Dim oShape As Shape
Dim oPresentation As Presentation
Dim oSlide As Slide
Dim oSelection As Selection
Set oPresentation = ActivePresentation
Set oSelection = Application.ActiveWindow.Selection
For Each oSlide In oPresentation.Slides
For Each oShape In oSlide.Shapes
If oShape.Type = msoEmbeddedOLEObject Then
If Left(oShape.OLEFormat.ProgID, 11) = "Excel.Sheet" Then
oSlide.Select
oShape.Select
oShape.OLEFormat.Activate
SendKeys "{ESC}"
End If
End If
Next oShape
Next oSlide
' If Not oSelection Is Nothing Then
' oSelection.Select
' End If
End Sub
When the macro gets to the oShape.Select statement I get the error message in the subject line of this posting. What does it mean and how do I fix it? I have no idea what view the message is referring to.
Second, I've written a similar little macro for Word. In that macro I needed the moral equivalent of the commented out code at the bottom of the macro to reselect whatever was originally selected before the macro started. Sadly in PowerPoint the Selection object doesn't have a Select method. Any suggestions?
Thirdly, if I can get this macro to work, I'd like to have it triggered whenever the PowerPoint presentation is opened. I was looking for the equivalent of the ThisWorkBook object that would have a Open event I could hook into but I see no such object in the VBE project explorer window. What am I missing?
TIA,
josh
I have a few questions:
First, I'm trying to write a simple macro that will loop through all of the slides in the open PowerPoint presentation and identify each embedded Excel worksheet and activate it (the reason for this isn't important but the worksheet is connected to a database and I want to get fresh data). My macro looks like this:
Sub UpdateExcelShapes()
Dim oShape As Shape
Dim oPresentation As Presentation
Dim oSlide As Slide
Dim oSelection As Selection
Set oPresentation = ActivePresentation
Set oSelection = Application.ActiveWindow.Selection
For Each oSlide In oPresentation.Slides
For Each oShape In oSlide.Shapes
If oShape.Type = msoEmbeddedOLEObject Then
If Left(oShape.OLEFormat.ProgID, 11) = "Excel.Sheet" Then
oSlide.Select
oShape.Select
oShape.OLEFormat.Activate
SendKeys "{ESC}"
End If
End If
Next oShape
Next oSlide
' If Not oSelection Is Nothing Then
' oSelection.Select
' End If
End Sub
When the macro gets to the oShape.Select statement I get the error message in the subject line of this posting. What does it mean and how do I fix it? I have no idea what view the message is referring to.
Second, I've written a similar little macro for Word. In that macro I needed the moral equivalent of the commented out code at the bottom of the macro to reselect whatever was originally selected before the macro started. Sadly in PowerPoint the Selection object doesn't have a Select method. Any suggestions?
Thirdly, if I can get this macro to work, I'd like to have it triggered whenever the PowerPoint presentation is opened. I was looking for the equivalent of the ThisWorkBook object that would have a Open event I could hook into but I see no such object in the VBE project explorer window. What am I missing?
TIA,
josh