2

(这似乎主要是 PowerPoint 2007 的特定问题,我无法在 PPT 2010 中轻松重现)

在本地复制的简单方法是:

1) Insert a shape into blank slide
2) Run command: ActivePresentation.Slides(1).Shapes(1).Delete in immediate window in Visual Studio. (You can alternatively delete through C#)
3) Undo the deletion in the PowerPoint presentation (do this non-programatically)

由于某种原因,您无法使用以下调用再次访问该形状:

ActivePresentation.Slides(1).Shapes(1) //Does not allow any methods/properties to work

我唯一远程获得的是,通过Selection.ShapeRange,您可以获得对该项目的引用,但大多数属性/方法在尝试使用该对象时会抛出 ComExceptions。

有谁知道我如何重新获得形状或以某种方式刷新演示文稿以获得一些干净的 Com 对象?

4

3 回答 3

1

我可以在 Ppt2007 SP3 中确认。尝试解决方法 .cut 和 .paste。之后我能够访问其他方法/属性。- 干杯,www.MSO-dlx.com

ActivePresentation.Slides(1).Shapes(1).Delete
Application.CommandBars.ExecuteMso "Undo" 'or manually Undo
ActiveWindow.Selection.SlideRange(1).Shapes(1).Cut 
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
ActiveWindow.Selection.SlideRange(1).Shapes(1).TextFrame.TextRange.Text = "ABC"
于 2013-10-24T12:37:30.093 回答
0

所以,我可以确认这是一个问题;即使在 2010 年,也找到了“更便宜”的替代方案:

Public Sub arf()

Dim arf As Slide
Dim shape As shape
Dim shapes As shapes

Set shapes = ActivePresentation.Slides(1).shapes
Set shape = shapes(2)
shape.Select

shape.Delete
Application.CommandBars.ExecuteMso "Undo"
MsgBox ("shape: " & shape.Name & ",Type: " & shape.Type)

Set shapes = ActivePresentation.Slides(1).shapes
Set shape = Nothing
Set shape = shapes(2)

' Cut and paste makes this work, but not required...
'shape.Select
'shape.Cut
'shapes.Paste

'Set shape = Nothing
'Set shape = shapes(2)

Set arf = shape.Parent
MsgBox ("slide: " & arf.Name)

End Sub
于 2014-01-16T16:42:44.517 回答
0

刚才我已经成功解决了这个问题,分享一下帮助很大的网页:https ://www.add-in-express.com/creating-addins-blog/2014/06/24/exception-hresult-0x800a01a8/

关键点是删除后释放对象,这与Skovly和sharkTwo完全一样。但是,我不知道如何使用C#做到这一点,链接给了我答案。

Marshal.ReleaseComObject(titleShape); titleShape = null;

像这样。

于 2016-07-24T11:01:27.897 回答