Mutuelinvestor
Mutuelinvestor

Reputation: 3548

Why Won't My Macro/VB run from in my PowerPoint presentation

I'm trying to add a little interaction to a PowerPoint presentation I'm working on. I'm written a little VB that will increase the size and position a particular chart object when the script runs. I'm tested the script in design mode and everything seems to work fine. When, however, I link my code to an action button and try to run it from within the slide show the code does not run. I do most of my VB in Excel so I have not run across this before. Can anyone suggest a fix for this. My code is set forth below:

 Sub MoveChart23()
    Dim s
    For Each s In ActiveWindow.Selection.SlideRange.Shapes
     If s.Name = "Chart 23" Then
      s.Top = 50
      s.Width = 620
      s.Left = 50
      s.Height = 400
     End If
    Next
End Sub

Thanks for your help.

Upvotes: 0

Views: 1894

Answers (1)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19077

Anyway, I think your problem is in the following line:

For Each s In ActiveWindow.Selection.SlideRange.Shapes

while you have no Selection in presentation mode. Depending on the way you run and control the whole presentation you should use something like this instead:

For Each s In ActiveWindow.Slides(1).Shapes

But if you need to refer to currently viewed slide you should go this way:

For Each s In SlideShowWindows(1).View.Slide.Shapes

Upvotes: 1

Related Questions