How to get the currently selected Custom Layout in a PowerPoint slide master using VBA?

I have a need to programmatically add shapes to a selected custom layout (as selected by a user).

Backtracking for a second, if a user is in the normal view and has selected one or more slides, then it's possible to find out how many and address them as follows:

' Get the number of selected slides

ActiveWindow.Selection.SlideRange.Count

' Get the slide index of the first selected slide

iSlideIndex = ActiveWindow.Selection.SlideRange(1).SlideIndex

and then add shapes to the first selected slide like this:

ActivePresentation.Slides(iSlideIndex).Shapes.AddTextbox _

  msoTextOrientationHorizontal, 0, 0, 10, 10

But when one tries to return the number of slides for a selected custom layout in the slide master view, a run-time error is returned:

Selection (unknown member) :  Invalid request. SlideRange cannot be constructed from a Master.

It's possible to select one or more custom layouts in the slide master view via the standard UI so does this mean there is no way to get the selected custom layout object from the object model? The closest I've got is this:

ActivePresentation.Designs(1).SlideMaster.CustomLayouts.Count

But can't see how to identify which of the custom layouts the user has selected.

 

Question Info


Last updated October 21, 2018 Views 588 Applies to:
Answer
Answer

See if this gets you started:

Sub tryThis()
Dim selCL As Object
Set selCL = ActiveWindow.View.Slide
selCL.Shapes.AddShape msoShape12pointStar, 10, 10, 20, 20
End Sub

You would probably want to check that you were in Slide Master View

If ActiveWindow.ViewType = 9 Then
If ActiveWindow.Panes(2).ViewType = ppViewSlideMaster Then

' You are

End If

End If

www.pptalchemy.co.uk

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.