3

我正在使用 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)':请求的操作目前被禁用”

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

4

1 回答 1

3

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

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
于 2013-10-11T00:35:00.180 回答