2
votes

I am trying to create a shape on a slide in PowerPoint (2010) VBA

I have created a button and this code:

Private Sub AddShape_Click()

Dim shp As Shape
Dim sld As Slide

Set sld = Application.ActiveWindow.View.Slide
Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=24, Top:=65.6, Width:=672, Height:=26.6)
'No Shape Border
shp.Line.Visible = msoFalse
'Shape Fill Color
shp.Fill.ForeColor.RGB = RGB(137, 143, 75)
shp.Fill.BackColor.RGB = RGB(137, 143, 75)

End Sub

When I run the presentation as a slide show and click the Add Shape button, I get the following error:

Run-time error '-2147188160 (80048240)': Application (unknown member): Invalid request. There is no currently active document window.

Everything I have found online indicates that this code should run OK.
All assistance appreciated!!!

Carolyn

3

3 Answers

2
votes

You will get the No Current Active Document Window error if you run your code while the presentation is in Slideshow (fullscreen) mode. Try this, instead:

set sld = Application.ActivePresentation.SlideShowWindow.View.Slide

1
votes

Things work differently in slide show view, but a couple very simple modifications will get this fixed up. Add this to the project and assign the AddShape_Click as an Action Setting (Run Macro):

Public Sub AddShape_Click(oBtn As Shape)
' It has to be public for the action setting to see it

Dim shp As Shape
Dim sld As Slide

'Set sld = Application.ActiveWindow.View.Slide
Set sld = oBtn.Parent

Set shp = sld.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=24, Top:=65.6, Width:=672, Height:=26.6)
'No Shape Border
shp.Line.Visible = msoFalse
'Shape Fill Color
shp.Fill.ForeColor.RGB = RGB(137, 143, 75)
shp.Fill.BackColor.RGB = RGB(137, 143, 75)

End Sub
0
votes

You can also get this error if PowerPoint recently crashed and is still running in the background. Try killing any such powerpoint processes using task manager and then try again.