Is This Content Helpful?
We're glad to know this article was helpful.
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.
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.
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
.Type = 3
.Name = "NewField"