Solved

Visio 2013 VBA - Switching layers with a macro - Turning PRINT layer ON and OFF

Posted on 2014-01-14
6
2,244 Views
Last Modified: 2014-01-15
I have three layers, Management, Technical and Voice.
When I switch views from Management to Technical to Voice,  I would ALSO like to be able to print that layer as well.  Currently when I switch layers.  I can see the current layer but I print some other layer.
Here is the code:
Option Explicit

Public Const LayerName_Mgmt$ = "Management"
Public Const LayerName_Tech$ = "Technical"
Public Const LayerName_Voice$ = "Voice"

Sub Management()
' Keyboard Shortcut: Ctrl+m
  '// Ctrl + M

  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  
  Call m_showAndHideLayers(pg, LayerName_Mgmt$)
  
  Set pg = Nothing
End Sub
Sub Switch_to_voice()
' switches to voice view
    'Enable diagram services
  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  
  Call m_showAndHideLayers(pg, LayerName_Voice$)
  
  Set pg = Nothing

End Sub
Sub Switch_to_technical()
' switches to technical view
' Keyboard Shortcut: Ctrl+t
    'Enable diagram services
  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  
  Call m_showAndHideLayers(pg, LayerName_Tech$)
  
  Set pg = Nothing

End Sub


'// ----- Private Procedures --------------------------------------------------
Private Sub m_showAndHideLayers(ByRef visPg As Visio.Page, _
                                ByVal sLayerNameToShow As String)
  
        If (visPg.Layers.Count = 0) Then
          Call MsgBox("The active page has no layers!" & vbCrLf & vbCrLf & _
                  "No changes to layers will be made.")
          GoTo Cleanup
        End If
        
  '// Try and get the target layer:
  Dim lyrTarget As Visio.Layer, lyr As Visio.Layer
  Set lyrTarget = m_getLayerByName(visPg, sLayerNameToShow)
    
        If (lyrTarget Is Nothing) Then
            '// Layer not found, so don't do anything at all
            Call MsgBox("Layer: '" & sLayerNameToShow & "' was not found!" & vbCrLf & vbCrLf & _
                        "No changes to layers will be made.")
            GoTo Cleanup
          Else
            '// The layer was found, turn it visible and active:
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 1
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 1
            
            '// Turn all the other layers invisible and inactive:
            Dim i As Integer
            For i = 1 To visPg.Layers.Count
            
              Set lyr = visPg.Layers.Item(i)
                    If (Not (lyr Is lyrTarget)) Then
                      lyr.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 0
                      lyr.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 0
                    End If
            Next i
          End If
 
Cleanup:
  '// Cleanup:
  Set lyrTarget = Nothing
  Set lyr = Nothing

End Sub

Private Function m_getLayerByName(ByRef pg As Visio.Page, _
                                  ByVal sLayerName As String) As Visio.Layer

  Set m_getLayerByName = Nothing
  
  Dim lyr As Visio.Layer
  For Each lyr In pg.Layers
    If (StrComp(sLayerName, lyr, vbTextCompare) = 0) Then
      Set m_getLayerByName = lyr
      Exit For
    End If
  Next lyr
  
  '// Cleanup:
  Set lyr = Nothing
  
End Function

Open in new window

0
Comment
Question by:brothertruffle880
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:fredvr666
ID: 39779636
This will work:
lyrTarget.CellsC(visLayerPrint).FormulaU = 1
0
 
LVL 11

Accepted Solution

by:
Visio_Guy earned 500 total points
ID: 39781538
So right beneath these lines:

  lyr.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 0
  lyr.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 0

Open in new window

add this line:

  lyr.CellsC(Visio.VisCellIndices.visLayerPrint).ResultIU = 1

Open in new window

0
 

Author Closing Comment

by:brothertruffle880
ID: 39781665
Thank you Visio guy!
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:brothertruffle880
ID: 39782174
Thank you Visio Guy.  Your instruction was flawlessly lucid.  I was able to do it even in my early-morning stupor.
0
 
LVL 11

Expert Comment

by:Visio_Guy
ID: 39782195
Too funny!
0
 

Author Comment

by:brothertruffle880
ID: 39783443
Oops.
Found and fixed a minor hitch.  Needed one more line of code.
    '// The layer was found, turn it visible and active:
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 1
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 1
            lyrTarget.CellsC(Visio.VisCellIndices.visLayerPrint).ResultIU = 1
            
            '// Turn all the other layers invisible and inactive:
            Dim i As Integer
            For i = 1 To visPg.Layers.Count
            
              Set lyr = visPg.Layers.Item(i)
                    If (Not (lyr Is lyrTarget)) Then
                        lyr.CellsC(Visio.VisCellIndices.visLayerVisible).ResultIU = 0
                        lyr.CellsC(Visio.VisCellIndices.visLayerActive).ResultIU = 0
                        lyr.CellsC(Visio.VisCellIndices.visLayerPrint).ResultIU = 0

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now