Programmatically export joined features to a shapefile


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 export a selected set of features from a joined feature class and table to a new shapefile 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. Start ArcMap.
  2. 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. Copy and paste the code below into the UIButtonControl's click event.
    Dim pMxDoc As IMxDocument
    Dim pFLayer As IFeatureLayer
    Dim pDataset As IDataset
    Dim pDSName As IDatasetName
    Dim pDispTable As IDisplayTable
    Dim pShapeFCName As IDatasetName
    Dim pShapeWSF As IWorkspaceFactory
    Dim pShapeWS As IDataset
    Dim pShapeWSName As IWorkspaceName
    Dim pQFilter As IQueryFilter
    Dim pExportOp As IExportOperation
    Set pMxDoc = Application.Document
    Set pFLayer = pMxDoc.FocusMap.Layer(0)
    Set pDispTable = pFLayer
    Set pDataset = pDispTable.DisplayTable
    Set pDSName = pDataset.FullName
    Set pShapeWSF = New ShapefileWorkspaceFactory
    Set pShapeWS = pShapeWSF.OpenFromFile("C:\temp", 0)
    Set pShapeWSName = pShapeWS.FullName
    Set pShapeFCName = New FeatureClassName
    pShapeFCName.Name = "Export_test"
    Set pShapeFCName.WorkspaceName = pShapeWSName
    ' Set up query sub fields: a comma-delimited list of the fields you want
    ' Or "*" for all fields in the joined feature class
    Dim strFld As String
    strFld = "*"
    Set pQFilter = New QueryFilter
    pQFilter.SubFields = strFld
    Set pExportOp = New ExportOperation
    pExportOp.ExportFeatureClass pDSName, pQFilter, Nothing, Nothing, pShapeFCName, 0
  1. Close the Visual Basic Editor.
  2. Add a feature class and table to ArcMap and join the table to the feature class based on a key field.
  3. Run the code by clicking the new UIButtonControl created in Step 2.

Article ID:000006578

  • ArcMap 8 x
  • 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