I am currently integrating Excel with Visio to auto-populate some elements diagrammatically. I have got so far with this effort but have got stuck between the documentation, macro recordings and actually doing what I want.
By recording macros I have found a way of selecting individual elements like so:
ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(216), visSelect
I have a loop in my script as follows:
For Each oItem In vsoDocument.Pages(sitePage).Shapes
If oItem.Name <> "Sheet.2" Then
'vsoDocument.Pages(sitePage).Select oItem.Item, visSelect ' NOW REMOVED
oItem.DeleteEx (visDeleteNormal)
Debug.Print oItem.Name
End If
Next oItem
UPDATE: Following from your responses and sanity checks you are right that I don't need to select the shape. I have amended the code to simply show oItem.DeleteEx (visDeleteNormal)
now and this works as expected. However I am left with a number of shapes on my sheet, such as a shape with the name "Ethernet.46". I don't know why some shapes were deleted and also why the page background was removed. I've found if I run my For loop once, add the background back in WITH vsoDocument.Pages(sitePage).BackPage
, then run my For loop again another 5 times in succession it finally removes all shapes.
QUESTION: Why is my For loop behaving unreliably?