2

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 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

I'm having trouble finding good documentation for PowerPoint VBA. How does slide show view differ and can you suggest any documentation? I put a command button on the slide and passed that into my sub, but there is no Parent property for a CommandButton. I'm prototyping app functionality using mockups made in PowerPoint and it has great ability to hyperlink within the presentation, but I need to add more functionality with VBA to closer approximate what the end feature(s) might feel like.
Why use a command button, unless you enjoy the extra pain that it engenders? ;-) Add an action button instead. Gives you the full button look, changes when pressed, etc, and will work with the above code if you assign the macro to it as an Action Setting.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.