Delete all shapes in layer

T

Thijs Schoemaker

Is it possible to delete all shapes in a variable layer?

Something like:

dim shp as visio.shape
dim layer as visio.layer

for each shp in layer("Name")
shp.delete
next

Any help very much appreciated!

Robert
 
C

Chris Roth [ Visio MVP ]

The logic is a bit strange, especially since shapes can belong to more than
one layer at a time.

Check this out:

Sub MarkShapesOnBobLayer()

' Add shapes to page. Put some of them on a layer named "Bob"

Dim s As Visio.Shape
Dim i As Integer, j As Integer
Dim lTarget As Visio.Layer, l As Visio.Layer

' This is the layer object in the page:
Set lTarget = ActivePage.Layers.Item("Bob")

For Each s In ActivePage.Shapes

' Check the layers that the shape belongs to:
For j = 0aTo s.LayerCount
Set l = s.Layer(j)
If l.NameU = lTarget.NameU Then s.Text = "Delete me"
Next j

Next

End Sub

Remember that if you really want to delete the shapes in this loop, you
should make a backwards for loop that goes from ActivePage.Shapes.Count to 1
step -1. Then, when you delete shapes, it won't mess up your loop.

--

Hope this helps,

Chris Roth
Visio MVP
 
D

David Parker

The new CreateSelection method could be used to select shapes on a layer,
then you can delete the selection?
 

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