我有一些VBA代码可以将EPS图片插入PowerPoint幻灯片,如下所示:
Function InsertPicture(filename as String) As Shape
Dim curSlide As Integer
Dim oShp As Shape, gShp As Shape
curSlide = ActiveWindow.View.Slide.SlideIndex
With ActivePresentation.Slides(curSlide).Shapes
Set oShp = .AddPicture(filename, msoFalse, msoTrue, 0, 0)
' Convert (by ungrouping) from EPS to Microsoft Office drawing object
oShp.Ungroup.Name = "GroupEPS"
' Return the new Microsoft Office drawing object
Set InsertPicture = ActivePresentation.Slides(curSlide).Shapes("GroupEPS")
End With
End Sub
Excel的等效插入图片功能是:
ActiveSheet.Pictures.Insert(filename).Select
如果需要引用该对象,则为此:
Dim oPic as Object
Set oPic = ActiveSheet.Pictures.Insert(filename)
但是当我尝试用以下行取消组合时,我收到错误438“对象不支持此属性或方法”
' For a selection
Selection.Ungroup
' For an object
oPic.Ungroup.Name = "GroupEPS"
但是,如果我在确认转换为Microsoft Office绘图对象后,右键单击正确插入到工作表中的图片,我可以成功取消组合。
为什么用户界面允许取消分组,但Excel VBA不允许(虽然PowerPoint VBA可以)并且有一种解决方法吗?
答案 0 :(得分:0)
只是一个猜测!
Sub unGrp()
Dim opic As ShapeRange
Dim filename As String
filename = "C:\Users\John\Desktop\telephone.eps"
ActiveSheet.Pictures.Insert(filename).Select
Set opic = ActiveWindow.Selection.ShapeRange
opic.Ungroup
End Sub
答案 1 :(得分:0)
一旦获得未分组的东西并将其保留为选中状态,请将b / g对象和其他对象留在组中;然后再次取消对其组件的分组并将其选中:
Selection.ShapeRange.Ungroup.Select
Selection.ShapeRange.Ungroup.Select
对几种不同的简单EPS进口和EMF / WMF进行了测试;适用于所有人。
然而,了解Office处理EPS的方式是堕胎;一直都是。至少这一次,他们出于一般的正当理由做错了。