calling any Visual basic guru's

Status
Not open for further replies.

Shadowspawn

[H]ard|Gawd
Joined
Sep 17, 2002
Messages
1,870
I am working on a network diagram with Visio 2013 and need a way to toggle some connectors off and on. The trick is that when one layer is turned off I want the other layer to turn on. Here is what I have at the moment:

Code:
Private Sub CommandButton1_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
' Debug.Print LayerName
  If LayerName = "Core 1 connections" Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
 LayerCellObj.Formula = False Or 0
  End If
Next
End Sub

Private Sub CommandButton2_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
' Debug.Print LayerName
  If LayerName = "Core 1 connections" Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
 LayerCellObj.Formula = True Or 1
  End If
Next
End Sub

Private Sub CommandButton3_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
' Debug.Print LayerName
  If LayerName = "Core 2 connections" Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
 LayerCellObj.Formula = True Or 1
  End If
Next
End Sub

Private Sub CommandButton4_Click()
Dim LayersObj As Visio.Layers
Dim LayerObj As Visio.Layer
Dim LayerName As String
Dim LayerCellObj As Visio.Cell
Set LayersObj = ActivePage.Layers
For Each LayerObj In LayersObj
LayerName = LayerObj.Name
' Debug.Print LayerName
  If LayerName = "Core 2 connections" Then
    Set LayerCellObj = LayerObj.CellsC(visLayerVisible)
 LayerCellObj.Formula = False Or 0
  End If
Next
End Sub

These are four buttons. The first two turn layer 1 (Core 1 connections) off or on. The second two do the same for layer 2 (Core 2 connections). I know I can do this in one button but my programming skills are nonexistent. I can figure it out over the course of a couple of days but I was hoping someone here could look and knock it out in five minutes.
 

socK

Supreme [H]ardness
Joined
Jan 25, 2004
Messages
4,197
if you're just looking to toggle / flip a boolean, you can logically negate it.
 

Shadowspawn

[H]ard|Gawd
Joined
Sep 17, 2002
Messages
1,870
Okay, sounds good, but how do I do that? I can grasp the theories easily enough, but I don't know the command language.

Can I reference the layer name directly? The current script that I am using looks like it searches through the layers until a matching name is found.
 

Shadowspawn

[H]ard|Gawd
Joined
Sep 17, 2002
Messages
1,870
I figured it out. I merged two of the buttons scripts so that one layer is disabled when the other is enabled. This gives me one button per layer which will work just fine.
 
Status
Not open for further replies.
Top