如何编写Visio宏以将形状从一个层移动到另一个层?

时间:2013-10-09 22:33:31

标签: vba visio visio-vba

我正在使用Visio 2003,我想编写一个宏,将所选项目移动到名为“已删除项目”的隐藏层。

我尝试录制一个宏,我得到的就是这个,它甚至没有告诉我如何与图层进行交互。 :(

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

编辑:

感谢。 SDK有一点帮助,但遗憾的是还不足以产生工作代码。我想我想要做的基本上是

Dim myLayer As Visio.Layer
Set myLayer = Application.ActiveWindow.Page.Layers.Add("Deleted Items")
myLayer.Add Application.ActiveWindow.Selection.ContainingShape, 1

但该代码不起作用。它给出了一个错误,显示“运行时错误'-2032465766(86db089a)':请求的操作目前被禁用”

我还希望从已经存在的任何图层中删除形状。我不知道该怎么做。

1 个答案:

答案 0 :(得分:2)

在VBA中,图层非常简单: 这将从页面中删除所有图层成员资格:

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

这会为删除图层添加形状

Dim myLayer As Visio.Layer
Set myLayer = Application.ActiveWindow.Page.Layers.Add("Deleted Items")
myLayer.Add Application.ActiveWindow.Selection(1), 1