2016-03-04 56 views
0

我有一個任務,我需要導入大量的emf圖形,將它們轉換爲形狀,取消組合並刪除最後面的對象。這個對象在我們正在做的事情中不需要。如果我知道它的名字是什麼,我可以用vba選擇它,我不認爲每次都是一樣的。使用via通過幻燈片選擇幻燈片背面的大多數對象

有沒有人有任何建議,如何選擇最後面的對象來刪除它?

任何建議將有所幫助。

+0

我似乎無法像手動操作一樣選擇圖形和「編輯圖片」。我嘗試命名圖形並選擇名稱,然後取消分組,但似乎沒有任何工作。 – Boyplunder

回答

0
Dim oSh As Shape 
Dim oBGShape As Shape 
Dim lZorder As Long 
Dim oTempRange As ShapeRange 
Dim x As Long 

Set oSh = ActivePresentation.Slides(1).Shapes("EMFGraphic") 
lZorder = oSh.ZOrderPosition 

' oSh.Ungroup returns a shaperange 
With oSh.Ungroup 
    ' ungrouping again is usually necessary 
    ' we want the first shape in the new shaperange 
    Set oTempRange = .Ungroup 
    Set oBGShape = oTempRange(1) 
End With 

oBGShape.Fill.Visible = True 
oBGShape.Fill.ForeColor.RGB = RGB(123, 123, 123) 
oBGShape.Left = 0 

MsgBox "The bg shape should now be at the left side of the slide and gray" 

oBGShape.Delete 


    While .ZOrderPosition > lZorder 
     .ZOrder (msoSendBackward) 
    Wend 

' If you want to regroup the shapes, you'll have to add them to an array 
' after the first ungroup 
' then use something like this to send the regrouped shape to the original 
' zorder, if need be: 
'  While .ZOrderPosition > lZorder 
'  .ZOrder (msoSendBackward) 
' Wend 

注意,每次運行這個時候,原來的組名將會丟失,不會與一個未做回,所以你必須在名稱每次重新申請到圖形,如果這個名字是你依賴它來工作的。