HOW TO
Instructions provide a code sample that shows how to add a new field to a shapefile or featureclass using VBA. The layer that the field will be added to must be selected in the Table of Contents before running the code.
Note:
Code in the Project's ThisDocument code module will only run in the current map document. If you want to store the code in all map documents, open the Normal.mxt ThisDocument code module instead.
Code:
Public Sub AddField()
Dim pMxDoc As IMxDocument
Dim pLayer As ILayer
Dim pFLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim NewField As IFieldEdit
Set pMxDoc = ThisDocument
Set pLayer = pMxDoc.SelectedLayer
Set pFLayer = pLayer
Set pFeatClass = pFLayer.FeatureClass
Set NewField = New Field
With NewField
.Type = 3
.Name = "NewField"
End With
pFeatClass.AddField NewField
End Sub
Get help from ArcGIS experts
Download the Esri Support App