Reputation: 215
I'm using Visio 2003 and I would like to write a macro that will move the selected items to a hidden layer called "Deleted Items".
I tried recording a macro and all I got was this, which doesn't even show me how to interact with layers. :(
Sub Move_to_Delete_Layer()
'
' Moves the selected item(s) to the "zDeleted Items" Layer (which typically remains hidden). This is basically an "undo-able" way to delete the item.
'
' Keyboard Shortcut: Ctrl+d
'
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Layer")
Application.ActiveWindow.Page.Shapes.ItemFromID(175).CellsSRC(visSectionObject, visRowLayerMem, visLayerMember).FormulaU = """9"""
Application.EndUndoScope UndoScopeID1, True
End Sub
Edit:
Thanks. The SDK helps a little, but unfortunately not enough to produce working code. I think what I want to do is essentially
Dim myLayer As Visio.Layer
Set myLayer = Application.ActiveWindow.Page.Layers.Add("Deleted Items")
myLayer.Add Application.ActiveWindow.Selection.ContainingShape, 1
But that code doesn't work. It gives me an error that says "Run-time error '-2032465766 (86db089a)': Requested operation is presently disabled"
And I also want to remove the shape from any layers it was already in. I'm not sure how to do that.
Upvotes: 4
Views: 4181
Reputation: 4327
Layers are pretty straightforward in VBA: This will remove all layer memberships from a page:
dim i as integer
for i = ShpObj.LayerCount to 1 Step -1
dim Lay as Visio.Layer
set Lay = ShpObj.Layer(i)
Lay.Remove ShpObj
next
This will add a shape to your delete layer
Dim myLayer As Visio.Layer
Set myLayer = Application.ActiveWindow.Page.Layers.Add("Deleted Items")
myLayer.Add Application.ActiveWindow.Selection(1), 1
Upvotes: 3