How To: Add an ArcInfo annotation layer to ArcMap with ArcObjects


This VBA example illustrates how to add an ArcInfo annotation layer to ArcMap programmatically using 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'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy this code into the UIButtonControl's click event.
'''This code loads an ArcInfo 7.x Annotation Coverage 

Dim a_wf As IWorkspaceFactory
Set a_wf = New ArcInfoWorkspaceFactory

Dim b_fc As IFeatureWorkspace
Set b_fc = a_wf.OpenFromFile("d:\coverages", 0)

Dim pWorkspace As IWorkspace
Set pWorkspace = b_fc

Dim pFeatClass As IFeatureClass
Set pFeatClass = b_fc.OpenFeatureClass("box:annotation")

'Note: If the annotation has a subclass, the syntax becomes

Dim pCovLayer As IFeatureLayer
Set pCovLayer = New CoverageAnnotationLayer
Set pCovLayer.FeatureClass = pFeatClass

Dim pDataset As IDataset
Set pDataset = b_fc
pCovLayer.Name = pDataset.Name

Dim pDoc As IMxDocument
Set pDoc = ThisDocument

pDoc.AddLayer pCovLayer