HOW TO
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
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
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
Get help from ArcGIS experts
Download the Esri Support App