Powerpoint Alchemy Amazing techniques and tips
Amazing techniques which will transform your use of PowerPoint presentations. Make your presentation stand out from the crowd!

About

Modifying Shapes with vba

You can modify shapes in several ways using vba. Examples include changing size, position, visibility and fill. First though you need to reference the shape you need to work with.

Often you will see code like this:

ActivePresentation.Slides(2).Shapes(3).Visible = False

This code will work well.... until you add slides or change the order of shapes on a slide. Once this happens the code will fail or do unexpected things as the slide and shape numbers will have changed.

Using Names

One answer is to use slide names and shape names which are not easily changed. All slides and shapes have default names which can be read with this vba.

Sub identifyme()
On Error GoTo errhandler
MsgBox "The shape is named " & ActiveWindow.Selection.ShapeRange.Name _
& Chr$(13) & "The slide is named " & ActiveWindow.Selection.SlideRange.Name
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub

Once you have the names you can use:

ActivePresentation.Slides("slidename").Shapes("shapename").Visible = False

You can also use vba to rename a shape or slide:

Sub nameshape()
On Error GoTo errhandler
ActiveWindow.Selection.ShapeRange.Name = InputBox("Name me")
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub

Sub nameslide()
On Error GoTo errhandler
ActiveWindow.Selection.SlideRange.Name = InputBox("Name me")
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub

 

Add In

This free AddIn will allow you to read names and change them in 2002/3! Simply download and unzip. Run the installer with PowerPoint Closed. NB It will work in 2007 but of course you don't need it here as you can use the selection pane. There are no instructions and no support but it's simple to use - select the shape and click the Name Shape toolbar.

DOWNLOAD HERE

Other Answers

To change a shape on the CURRENT slide in slide show view:

ActivePresentation.SlideShowWindow.View.Slide.Shapes("shapename").Visible = False

To get a reference to the current slide:

Dim i As Integer
i = ActivePresentation.SlideShowWindow.View.CurrentShowPosition

You can then use "i" to change shapes on eg the NEXT slide

ActivePresentation.Slides(i+1).Shapes("shapename").Visible = False

Don't know how to use vba? See here



 


This website is sponsored by Technology Trish Ltd
© Technology Trish 2007
Registered in England and Wales No.5780175