This sample demonstrates how to programmatically enable "Lock Labels" for all the data frames in an MXD. A placement run should take place before running this command, otherwise there will be no labels to "lock." Refreshing the data frame and letting it complete will result in a full placement run. This sample takes advantage of generic interfaces that work on both the ESRI Standard Label Engine and ESRI Maplex Label Engine, so the sample will work with or without Maplex.
How to use
- Copy and paste the sample code into the VBA Editor.
- Run the Macro.
Public Sub EnableLabelLock()
Dim pMxDoc As IMxDocument
Dim pMaps As IMaps
Dim pMap As IMap
Dim pMapOverposter As IMapOverposter
Dim index As Long
Dim pOverposterOptions As IOverposterOptions
Set pMxDoc = ThisDocument
Set pMaps = pMxDoc.Maps
'loop through all the maps
For index = 0 To pMaps.Count - 1
Set pMap = pMaps.Item(index) 'get the map at the current index
Set pMapOverposter = pMap
Set pOverposterOptions = pMapOverposter.OverposterProperties
pOverposterOptions.EnableLabelCache = True
Next index
End Sub