Layers problems: Same ID

S

Sachin

I am working on a Visio drawing with many lines. The lines are colour-
coded, into about 6 different colours. I created layers for each
colour, and my goal was to create a set of macros where I could
selectively show different types of lines. I have a small legend in
the corner with a sample line for each colour, and by double clicking
on a given line you can toggle visibility for that type. It is very
simple.

What I did was record a macro for an example (pink). The macro
consisted simply of me going to 'Layer Properties' and unchecking the
box that says 'visible' for pink. Then I did the same thing except
checked it back. I edited the code by throwing in an if-statement and
the macro was done.

The issue I am having is that after doing that for each colour, I
experienced weird problems. For example, this is the code for the
black line macro (after I edited it with the if statement and cleaned
it up a bit):

Sub BlackLines()

Dim vsoLayer1 As Visio.Layer
Dim UndoScopeID2 As Long
UndoScopeID2 = Application.BeginUndoScope("Layer Properties")
Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item(4)

' checks which switch to execute
If vsoLayer1.CellsC(visLayerVisible).FormulaU = "1" Then
vsoLayer1.CellsC(visLayerVisible).FormulaU = "0"
Else
vsoLayer1.CellsC(visLayerVisible).FormulaU = "1"
End If

Application.EndUndoScope UndoScopeID1, True

End Sub

-----

All the macros are similar (they just have different Item IDs), but
some of the macros are identical! My PinkLines macro also uses the Item
(4) identification.

I know this is not a typo or anything because to check to make sure I
wasn't crazy, I recorded a macro that turned off visibility for black
lines. Without even looking at the code, I manually turned the
visibility for black lines back on, and ran the macro. It took out the
pink lines.

Has anyone experienced something like this before? Any help or ideas
would be great.
Thanks
 
P

Paul Herber

I am working on a Visio drawing with many lines. The lines are colour-
coded, into about 6 different colours. I created layers for each
colour, and my goal was to create a set of macros where I could
selectively show different types of lines. I have a small legend in
the corner with a sample line for each colour, and by double clicking
on a given line you can toggle visibility for that type. It is very
simple.

click in the page itself to ensure no shape is selected, the
menu Window -> Show Shapesheet
and look at the Layers section. Are the layers in the order you expect
them? You should access the layers by name rather than by index.

Set vsoLayer1 = Application.ActiveWindow.Page.Layers.Item("pink")
etc.
 

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