0

我正在为 PowerPoint 开发一个插件,当 PowerPoint 在 SlideMaster 视图中时,它会与之交互。

取决于内容,我需要在 SlideMaster 或 CustomLayouts 上选择 Shapes。

我已经设法在 CustomLayouts 上选择它们,但是当 Shapes 位于 SlideMaster 上时,我没有设法做到这一点。

我尝试使用以下方法:

第一种方法

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

此方法仅在用户手动选择特定幻灯片母版时有效。否则我得到例外:

“形状(未知成员):无效请求。要选择形状,其视图必须处于活动状态。”

第二种方法

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

当我使用这种方法时,我得到以下异常:

尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

我没有找到任何方法来激活 SlideMaster 以选择其上的形状。

有没有办法做到这一点?

先感谢您。

4

1 回答 1

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.

于 2016-02-08T09:36:23.397 回答