VBA - removing object from layer

V

vespasiandamascus

I am using the following macro to selectively add connectors to a
specific layer. There is a complication though: every connector on my
page belongs to a layer called 'connector', which I don't want. I want
to somehow remove everything from that layer without deleting the
shapes, or remove every shape from that layer.

Is there a variation of this code that will remove something from a
layer? I have tried many permutations but with no success. Thanks in
advance!

---

Public Sub MoveToLayer()

Dim objShps As Visio.Selection, objShp As Visio.Shape
Dim objLayers As Visio.Layers, objLayer As Visio.Layer
Dim i As Integer

'get the Selection
Set objShps = Visio.ActiveWindow.Selection

'get the layers collection
Set objLayers = Visio.ActivePage.Layers
Set objLayer = objLayers("Shapes")

For i = 1 To objShps.Count
Set objShp = objShps(i)
objLayer.Add objShp, 0
Next i

End Sub
 
A

AlEdlund

shapes often bring along a default layer with them. I usually add something
like this just after
I drop them on the page

visShape.CellsSRC(visSectionObject, visRowLayerMem,
visLayerMember).FormulaForceU = """"""

hth,
al
 
V

vespasiandamascus

I am familiar with that line of code, but I'm wondering if there is
anything I can do about it now, after the connectors are already on
the page?

Thanks
 
A

AlEdlund

If your attempting to ensure that the connector is on only one layer then
put it between
these two instructions

Set objShp = objShps(i)

objShpe.CellsSRC(visSectionObject,
visRowLayerMem, visLayerMember).FormulaForceU = """"""

objLayer.Add objShp, 0

al
 
P

Paul Herber

I am familiar with that line of code, but I'm wondering if there is
anything I can do about it now, after the connectors are already on
the page?

If it's only a one-off operation
menu View -> Layer Properties
and turn off the visibility of all layers except the one you want to
delete
Select all the shapes
menu Format -> Layer
and remove the unwanted layer
menu View -> Layer Properties
and restore the layer visibility
Now you can delete the unwanted layer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top