2013-10-09 52 views
1

我正在使用Visio 2003,我想編寫一個宏將所選項目移動到名爲「已刪除項目」的隱藏層。如何編寫Visio宏將圖形從一個圖層移動到另一個圖層?

我試着錄製一個宏,我得到的只是這個,它甚至沒有告訴我如何與層交互。 :(

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)':請求的操作目前被禁用「

而且我還想從y層已經進入。我不知道該怎麼做。

+0

對不起沒有安裝Visio 2003但您可能會發現[Visio 2003 SDK](http://msdn.microsoft.com/en-us/library/office/aa272275(v = office.11​​).aspx)有用。 – PatricK

回答

1

層是非常簡單的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 
相關問題