OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

Why doesn't the recorded macro work in Slide Show Mode?

A frequently  asked question - "I recorded a macro which changes the certain attributes of a shape on the slide. It works fine in the Slide View mode, but not the View Show mode. What is wrong?"

Nothing is wrong. It's the way PowerPoint works. If you record a macro to change the Fore colo(u)r of a shape (Rectangle 4) on the slide, the code generated would be:

 

Sub Macro1()
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 4").Select
With ActiveWindow.Selection.ShapeRange
     .Fill.Visible = msoTrue
     .Fill.Solid
     .Fill.ForeColor.RGB = RGB(204, 255, 204)
End With
End Sub

The code generated clearly works with the Selection. However during the Slide Show mode you cannot work with the Selection. You need to explicitly reference the shape/object by it's name/index value. Modify the earlier recorded code as shown below

  ' Reference the shape by it's name
Sub Macro1()
With ActivePresentation.Slides(1).Shapes("Rectangle 4")
     .Fill.Visible = msoTrue
     .Fill.Solid
     .Fill.ForeColor.RGB = RGB(204, 255, 204)
End With
End Sub


------ OR ------

  ' Reference the shape by it's Index value
Sub Macro1()
With ActivePresentation.Slides(1).Shapes(1)
     .Fill.Visible = msoTrue
     .Fill.Solid
     .Fill.ForeColor.RGB = RGB(204, 255, 204)
End With
End Sub

Run the show and test the macro.

NOTE: Shyam's ToolBox offers a tool that'll give you the name of the shape/slide. You could rename it too to something meaningful Download it from http://skp.mvps.org/toolbox/index.html


 

Copyright 1999-2014 (c) Shyam Pillai. All rights reserved.