Is This Content Helpful?
We're glad to know this article was helpful.
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.
Open "c:\geodata\files\headings.txt" For Input Access Read As #1
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
Set pFeatureLayer = pLayers.Next
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.
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.