HOW TO

Change the selected object in ArcCatalog using VBA

Last Published: April 25, 2020

Summary

This article contains a code sample that shows how to change the selection in ArcCatalog using VBA.

Procedure



  1. Start ArcCatalog.
  2. Open the Visual Basic Editor.

    In ArcCatalog, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Normal.gxt. Expand ArcCatalog Objects and right-click ThisDocument > View Code.
    [O-Image] ArcCatalog Project Explorer
  4. Copy the following code into the code module:

    Code:
    Sub ChangeSelectionInArcCatalog()
    Dim pGApp As IGxApplication
    Dim pGxSel As IGxSelection
    Dim pEnumGxObj As IEnumGxObject
    Dim pGxObj As IGxObject
    Dim ln As Long

    Set pGApp = Application
    'Specify the file that is to be selected
    'In this case it is a personal geodatabase table
    Set pGxObj = pGApp.Catalog.GetObjectFromFullName _
    ("c:\testing\table.mdb\accidentdata", ln)
    Set pGxSel = pGApp.Selection
    pGxSel.SetLocation pGxObj, Nothing
    'Refresh the catalog.
    'By setting the path it will only refresh that folder
    pGApp.Refresh "c:\testing"
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. In ArcCatalog, select Tools > Macros > Macros to display the Macros dialog box.

    B. Select a macro and click Run.

Article ID:000006286

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