Microsoft KB Archive/254924

= Visio: How to Set the Visible Property for Layers in a Visio Document =

PSS ID Number: 254924

Article Last Modified on 6/4/2003

-

The information in this article applies to:


 * Microsoft Visio 2000 Standard Edition
 * Microsoft Visio 2000 Professional Edition
 * Microsoft Visio 2000 Technical Edition
 * Microsoft Visio 2000 Enterprise Edition
 * Microsoft Visio Standard 5.0x
 * Microsoft Visio Professional 5.0x
 * Microsoft Visio Technical 5.0x
 * Microsoft Visio Enterprise 5.0x
 * Microsoft Visual Basic for Applications

-



This article was previously published under Q254924



SUMMARY
This article provides sample Visual Basic for Applications code that demonstrates how to set the Visible property for layers in a Visio document.



Sample Code
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

http://www.microsoft.com/partner/referral/

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

The following code resides in the ThisDocument module: Option Explicit Public Sub ShowHideLayers 'Load the Show/Hide Layers dialog. '   frmAvailLayers.Show End Sub Public Sub ShowLayer(LayerName As String) 'Show the selected layer, called by Show/Hide Layers dialog. Dim visLayer As Visio.Layer Dim visPage As Visio.Page Dim visLayerCell As Visio.Cell 'Get the active page and layer name as it was passed. '   Set visPage = Visio.ActivePage Set visLayer = visPage.Layers(LayerName) 'Get the Visible cell for the specified layer. '   Set visLayerCell = visLayer.CellsC(visLayerVisible) 'Set the value of the Visible cell to True show the specified layer. '   visLayerCell = True End Sub Public Sub HideLayer(LayerName As String) 'Hide the selected layer, called by Show/Hide Layers dialog. Dim visLayer As Visio.Layer Dim visPage As Visio.Page Dim visLayerCell As Visio.Cell 'Get the active page and layer name as it was passed. '   Set visPage = Visio.ActivePage Set visLayer = visPage.Layers(LayerName) 'Get the Visible cell for the specified layer. '   Set visLayerCell = visLayer.CellsC(visLayerVisible) 'Set the value of the Visible cell to False to hide specified layer. '   visLayerCell = False End Sub The following code resides in the frmAvailLayers form: Option Explicit Dim LayerName As String Private Sub cmdShowHide_Click 'Call ShowLayer or HideLayer based on the status of the selected layer. '   If cmdShowHide.Caption = "Show" Then ThisDocument.ShowLayer (LayerName) Else ThisDocument.HideLayer (LayerName) End If   'Hide the Show/Hide Layers dialog. '   frmAvailLayers.Hide End Sub Private Sub lstLayers_Click Dim visLayer As Visio.Layer Dim visLayerCell As Cell 'get the selected layer name '   LayerName = lstLayers.Value 'Check the selected layer's visible status in Visio. '   Set visLayer = ThisDocument.Application.ActivePage.Layers(LayerName) 'Get the Visible cell for the layer. Set visLayerCell = visLayer.CellsC(visLayerVisible) 'Update UI based on the status of the layer's Visible property. '   If visLayerCell.Formula = 0 Then cmdShowHide.Caption = "Show" cmdShowHide.Enabled = True Else cmdShowHide.Caption = "Hide" cmdShowHide.Enabled = True End If End Sub Private Sub UserForm_Activate 'Get the list of layers and add them to the layer listbox. Dim visLayers As Visio.Layers Dim i As Integer Set visLayers = ThisDocument.Application.ActivePage.Layers 'Add every layer on the active page to the layer listbox. '   For i = 1 To visLayers.Count lstLayers.AddItem visLayers(i).Name Next i   'Disable command button. '   cmdShowHide.Enabled = False End Sub

Keywords: kbdtacode kburl KB254924

Technology: kbVBASearch kbVisio2000Search kbVisio500xSearch kbVisioSearch kbZNotKeyword3 kbZNotKeyword6

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.