Set visibility for all the layers in ArcMap to false


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.

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


  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​
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

  'refresh the table of contents

End Sub

Article ID:000004944

  • 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