HOW TO

Set visibility for all the layers in ArcMap to false

Last Published: April 25, 2020

Summary

Note:
This article pertains to ArcGIS versions 8.x and 9.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.

Instructions provided describe how to create a button that sets the visibility for all layers in the ArcMap Table of Contents to false, using VBA and ArcObjects.

Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Procedure

  1. Open ArcMap.
  2. Open the Visual Basic Editor. In ArcMap, select Tools > Macros > Visual Basic Editor.
  3. Create a new UIButtonControl: How To: Create a new UIButtonControl​
Note:
For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  1. Right-click the UIButtonControl and select View Source.
  2. Paste this code into the UIButtonControl's click event:
Public Sub LayerVis()

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFeatureLayer As IFeatureLayer
Dim pGroupLayer As IGroupLayer
Dim i As Integer

'get the document and map
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

'loop through the layers and make them visible or not

For i = 0 To pMap.LayerCount - 1
If TypeOf pMap.Layer(i) Is IGroupLayer Then
    Set pGroupLayer = pMap.Layer(i)
    pGroupLayer.Visible = False
    ElseIf TypeOf pMap.Layer(i) Is IFeatureLayer Then
    Set pFeatureLayer = pMap.Layer(i)
    pFeatureLayer.Visible = False
    End If
  Next i

  'refresh the map
  pMxDoc.ActiveView.Refresh

  'refresh the table of contents
  pMxDoc.UpdateContents

End Sub

Article ID:000004944

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic