HOW TO
Steps to develop VBA code to update Table Of Contents (TOC) symbology headings from a text file prior to inserting a legend in a map document.
Code:
Open "c:\geodata\files\headings.txt" For Input Access Read As #1
Code:
Dim i As Integer
Dim j As Integer
Dim pLegendInfo As ILegendInfo
Dim pLegendGroup As ILegendGroup
Dim strMyHeading As String
For i = 0 To pMap.LayerCount - 1
Set pLegendInfo = pFeatureLayer
For j = 0 To pLegendInfo.LegendGroupCount - 1
Set pLegendGroup = pLegendInfo.LegendGroup(j)
Input #1, strMyHeading
pLegGroup.Heading = strMyHeading
Next j
Set pFeatureLayer = pLayers.Next
Next i
Close #1
pMxDoc.UpdateContents
Warning:
Run this code before you insert a legend from the Insert menu. Since this code does not capture legend properties, running it after inserting the legend would not update the legend graphic and you'd have to be rebuild from scratch.
Note:
This is not ESRI supported code. Use it at your own risk. Make a backup of your data before running this code and carefully check the output. This is just example code with no real error checking. It is meant to be a guide to develop code specific to your data inputs and desired outputs.
Article ID:000002429
Get help from ArcGIS experts
Download the Esri Support App