HOW TO

Use VBA to open the new shapefile or new feature class dialog box depending on selected location

Last Published: April 25, 2020

Summary

Instructions provided describe how to open the new feature class or new shapefile dialog box programmatically using VBA code. The code can be executed with a button-click in ArcCatalog.If the location is a folder, the script opens the New Shapefile dialog box.If the location is a geodatabase or feature dataset, the script opens the New Feature Class dialog box.

Procedure

Follow the steps below:

  1. Start ArcCatalog.
  2. Create a new UIButtonControl.

    A. Select Tools > Customize to open the Customize dialog box.
    B. Select the Commands tab.
    C. Select [UIControls] from the Categories list box.
    D. Select Untitled from the Save In drop-down list to save the button to this map document. Select Normal to save the button to all ArcMap documents on the machine.
    E. Click New UIControl.
    F. Select UIButtonControl and click Create.
    G. Drag the new UIButtonControl to the toolbar of choice.
    H. Close the Customize dialog box.



    Note:
    If a UIButtonControl already exists with the name 'UIButtonControl1'. To change the name of the UIButtonControl, it is necessary to make the change to the UIButtonControl code portion below, accordingly, before the button can be used.

  3. Open Visual Basic Editor.

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

  4. In the Project Explorer window, expand the 'Normal (Normal.gxt)' item and select ArcCatalog Objects > ThisDocument. Right-click and select View Code.
  5. Paste the following code into the code module:

    Code:
    ' Notes:
    ' open new shapefile or geodb feature class dialog depending on the selected item
    ' if a folder is selected, it will be the shapefile dialog
    ' if a geodatabase (sde or personal) or feature dataset is selected, it will be a geodb feature class dialog

    Private Sub UIButtonControl1_Click()
    Dim pGxApp As IGxApplication
    Set pGxApp = Application
    Dim pSelObj As IGxObject
    Set pSelObj = pGxApp.SelectedObject
    ' Debug.Print pSelObj.Category
    Dim location As String
    location = pSelObj.FullName
    ' Debug.Print location
    Dim pCmdItem As ICommandItem
    If pSelObj.Category = "Personal Geodatabase" _
    Or pSelObj.Category = "Personal Geodatabase Feature Dataset" _
    Or pSelObj.Category = "Spatial Database Connection" _
    Or pSelObj.Category = "SDE Feature Dataset" Then
    Set pCmdItem = Application.Document.CommandBars.Find(ArcID.Gx_NewFeatureClassMenu)
    pCmdItem.Execute
    ElseIf pSelObj.Category = "Folder" Or _
    pSelObj.Category = "Folder Connection" Then
    Set pCmdItem = Application.Document.CommandBars.Find(ArcID.Gx_NewShapefileMenu)
    pCmdItem.Execute
    Else
    Exit Sub
    End If
    End Sub

  6. Click the new button to open the Create New Shapefile or New Feature Class dialog.

Article ID:000008647

Software:
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic