PDA

View Full Version : Can't move to layer; only adds layer instead



JoeMarfice
05-15-2012, 09:04 AM
I'm trying to move a selected shape from one layer to another. Instead, all I can do is to add the 2nd layer to the existing layers of the shape.

Sub MoveToLayer()
Dim shp As Shape
Set shp = ActiveWindow.Selection.Item(1)
ActivePage.Layers("Weldments N Trailing End").Add shp, 0
End Sub
After running this code, the selected shape is shown as having "multiple layers", including the original layer.

The help for Add in this context reads:

expression.Add(SheetObject, fPresMems)

expression A variable that represents a Layer object.

Name Required/Optional Data Type Description
SheetObject Required (IVSHAPE) The new Shape object added to the Layer object.
fPresMems Required Integer Zero to remove subshapes from any previous layer assignments; non-zero to preserve layer assignments

Visio 2007 on Windows 7, BTW.

JoeMarfice
05-15-2012, 12:45 PM
This has got to be the single clunkiest, stupidest-looking piece of code I've ever been forced to use, but it seems to work:

Sub MoveToLayer()

Dim strLayer As String
Dim shp As Shape

Set shp = ActiveWindow.Selection.Item(1)

strLayer = """" & ActivePage.Layers("B").Index - 1 & """"
shp.CellsSRC( _
visSectionObject, visRowLayerMem, visLayerMember).FormulaForceU _
= strLayer

End Sub