Total purge of a layer (Visio 2007)

Started by Archangelos, February 19, 2021, 03:55:58 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Archangelos

When a use deletes a layer (either manually or via code) only single layer objects can get deleted.

For example, I have Layer1, Layer2, Layer3. Let's say that some objects exist to one of these layers. However, some objects exist in more than one layers. Some exist in both Layer1, Layer2. Others exist in Layer1, Layer3 and so on.

If I delete Layer1 then objects that exist in Layer1 only will get deleted. However, an object that exists in both Layer1, Layer2 will not get deleted. That's my problem.

I want to purge anything associated with Layer1. According to my understanding, the only way is to select Layer1, loop through all objects in Layer1 and delete them.

I tried, I googled and "played" but I can't. Any help?

Surrogate

#1
Quote from: Archangelos on February 19, 2021, 03:55:58 PM
I tried, I googled and "played" but I can't. Any help?
Hi, Archangelos !
How you iterate these layers from first to last or from last to first ?
Sub ForArchangelos()
Dim lyrs As Layers, LYR As Layer
Set lyrs = ActivePage.Layers
For I = lyrs.Count To 1 Step -1
Set LYR = lyrs.Item(I)
LYR.Delete True
Next
End Sub

Archangelos

I do not need to iterate through the Layers. I have many layers I want to target a specific layer.

I am thinking something like the following.


s=activepage.layers.item("Layer1")

for each objjj in s.objects
     objjj.delete
next objjj

Archangelos

Quote from: Surrogate on February 19, 2021, 04:20:17 PM
Quote from: Archangelos on February 19, 2021, 03:55:58 PM
I tried, I googled and "played" but I can't. Any help?
Hi, Archangelos !
How you iterate these layers from first to last or from last to first ?

I see what you mean! Yes! I have faced that in Excel. By the way, in Excel I think of myself powerful but on other MS Office application I feel a loser. :(

Yes, when you need to delete you start from last to first object. I have seen it in MS Excel when I needed to delete some lines from a preadsheet.

However, that's not the issue in my case.

wapperdude

I would think that's normal behavior.  An object on two or more layers presumably is needed on the non-deleted layers.  If you are trying to delete all shapes that are specific to a given layer, you need to search thru the shapes and which is on the undesired layer and delete the shape.  Then, you may delete the layer.

Visio 2019 Pro