How To: Programmatically export joined features to a shapefile


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.



  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'
  3. Right-click the UIButtonControl and select View Source.
  4. 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
  5. Close the Visual Basic Editor.
  6. Add a feature class and table to ArcMap and join the table to the feature class based on a key field.
  7. Run the code by clicking the new UIButtonControl created in Step 2.

Related Information