1

New in VBA for ppt. (used to do more Excel vba). Below macro is really simple and works fine in normal mode , when I run it in PowerPoint's VBA editor. (Will add a blue rectangle shape in the center of the screen)

To work in slide show, I assigned the macro to a random shape through the action setting option but nothing happen really. Thanks

Sub Rdmrectangle()

Dim sld As Slide
Dim shp As Shape
Dim SlideIndex As Long

SlideIndex = ActiveWindow.View.Slide.SlideIndex

Set sld = ActivePresentation.Slides(SlideIndex)

Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=50, Top:=50, Width:=100, Height:=200)

With ActivePresentation.PageSetup
shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
End With

shp.Fill.ForeColor.RGB = vbBlue

shp.ZOrder msoBringToFront
End Sub
Emoups
  • 11
  • 1

1 Answers1

0

If you need this to work in slide show mode, you can work with ActivePresentation.SlideShowWindow.View.

Sub Rdmrectangle()

    Dim sld As slide
    Set sld = ActivePresentation.SlideShowWindow.View.Slide

    Dim shp As Shape
    Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
        Left:=50, Top:=50, Width:=100, Height:=200)

    With ActivePresentation.PageSetup
        shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
        shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)
    End With

    shp.Fill.ForeColor.RGB = vbBlue
    shp.ZOrder msoBringToFront
End Sub
BigBen
  • 46,229
  • 7
  • 24
  • 40