0

I am working on a plugin for PowerPoint ,which interacts with it when PowerPoint in SlideMaster view.

Depends on content, I need to select Shapes on either SlideMaster or on CustomLayouts.

I have managed to Select them on CustomLayouts, but I did not manage to do that, when Shapes are located on SlideMaster.

I tried to use following approaches:

First approach

presentation.Designs[1].SlideMaster.Shapes[1].Select();

This approach works only when user manually selects a particular slide master. Otherwise i get the exception:

"Shape (unknown member) : Invalid request. To select a shape, its view must be active."

Second approach

presentation.Application.ActiveWindow.View.Slide = document.Designs[2].SlideMaster;

When I use this approach I get the following exception:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

I did not find any ways to activate a SlideMaster to select shapes on it.

Are the any ways to do that?

Thank you in advance.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

1

To select anything in PowerPoint, you need to manage the window's view. This will allow you to select the first shape on the slide master by switching the view first:

For PowerPoint 2007:

CommandBars.ExecuteMso ("ViewSlideMasterView")
DoEvents
ActivePresentation.SlideMaster.CustomLayouts(1).Select
SendKeys ("{UP}")

The non-SendKeys method that should work but doesn't on 2007 (tested OK on PowerPoint 2016):

ActiveWindow.ViewType = ppViewMasterThumbnails
With ActiveWindow.View.Slide
  .Shapes(1).Select
End With

As an aside, do you actually need to select the object? Depending on what you're doing with it, you might not even need to select it and hence don't need to manage window views. For example, if you want to copy it or format it, you don't need to select it. If you want to group it with something else then you do need to select it first.

Jamie Garroch - MVP
  • 2,839
  • 2
  • 16
  • 24
  • Thank you very much for you answer. I have tried to change the ViewType of the ActiveWindow. When I did that all miniatuars are dissapeared. After that, I saw only the active slide, without any slide thumbnails. No, I do not need to copy the objects, I need to select either Shapes or TextRanges. Depends on Content. – Dmitry Gavrilov Feb 08 '16 at 09:41
  • Actually my plugin go through all content of presentation and retrieve the text. The plugin allows user to navigate through presentation by clicking on text. So can be situation when user would like to select either shape or text on Slide Master or Custom Layout. That is why I need to have possibility to activate SlideMaster somehow. – Dmitry Gavrilov Feb 08 '16 at 09:50
  • Actually, I just tried to configure ppViewMasterThumbnails. I got the following exception "DocumentWindow (unknown member) : Invalid enumeration value." Will this approach help if presentation has two or more SlideMasters? – Dmitry Gavrilov Feb 08 '16 at 10:34
  • It looks like you need to switch the view in two steps for 2007 so I've updated the code snippet to reflect this. – Jamie Garroch - MVP Feb 09 '16 at 09:16
  • Hi, thank you for your answer. Unfortunately it didn't help. I got the same exception. – Dmitry Gavrilov Feb 09 '16 at 09:42
  • Grrr. 2007 isn't behaving as per newer versions! I've changed the code to use a workaround to the limitation you're seeing. – Jamie Garroch - MVP Feb 09 '16 at 10:39
  • Hi, Thank you very much for your answer. The last approach helped me. Thanks a lot! – Dmitry Gavrilov Feb 13 '16 at 21:26