How To: Programmatically export joined features to a shapefile
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 export a selected set of features from a joined feature class and table to a new shapefile 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
- Start ArcMap.
- Create a new UIButtonControl: How To: Create a new UIButtonControl
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
- Right-click the UIButtonControl and select View Source.
- 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
- Close the Visual Basic Editor.
- Add a feature class and table to ArcMap and join the table to the feature class based on a key field.
- Run the code by clicking the new UIButtonControl created in Step 2.
Last Published: 7/31/2019
Article ID: 000006578