一般光靠操作整個圖形實現變化是不太可能的,因此考慮化整為零,把其中兩個組合圖形從整體中分離,然後再進行組合操作即可。首先嘗試通過宏記錄方式查看代碼,得到分解後的形狀操作宏代碼如下所示:
Sub Macro1()
Dim UnDOScopeID1 As Long
UndoScopeID1 = Application.BeginUnDOScope("移動對象")
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(60), visSubSelect
Application.ActiveWindow.Selection.Move 0.405512, -0#
ActiveWindow.Selection.RemoveFromGroup
Application.EndUndoScope UnDOScopeID1, True
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(25), visSubSelect
Application.ActiveWindow.Selection.Move 0.314961, -0#
Dim UnDOScopeID2 As Long
UndoScopeID2 = Application.BeginUnDOScope("移動對象")
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(60), visSelect
Application.ActiveWindow.Selection.Move -0.688976, 0#
ActiveWindow.DeselectAll
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(22), visSelect
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(60), visSelect
ActiveWindow.Selection.AddToGroup
Application.EndUndoScope UnDOScopeID2, True
End Sub
至此,完成萬裡長征第一步,也證實分解後的圖形,可以通過移動位置的方式實現,雖然定位形狀我們不能靠 ActiveWindow.Page.Shapes.ItemFromID(60)來定位,但是我們可以通過埋在形狀中的設備類型參數來實現形狀的定位的(這裡我在設計模具的時候,把兩個形狀的的設備類型屬性分別設置為“閥A"和”閥B“)。