HOW TO

Programmatically change the properties of a text element

Last Published: April 25, 2020

Summary

Instructions provided change the properties of a text element using an ArcObjects sample.

Procedure



  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. Expand Project.mxt in the Project Explorer window, select ArcMap Objects > ThisDocument, right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Note:
    Code in the Project's ThisDocument code module will only run in the current map document. To store the code in all map documents open the Normal.mxt ThisDocument code module.

  4. Copy the following code into the code module.

    Code:
    Sub ChangeFont_of_TextElements()

    Dim pMxDoc As IMxDocument
    Dim pLayout As IPageLayout2
    Dim pGraphicsContainer As IGraphicsContainer
    Dim pElement As IElement
    Dim pTextElement As ITextElement

    Set pMxDoc = ThisDocument
    Set pLayout = pMxDoc.PageLayout
    Set pGraphicsContainer = pLayout

    'create symbol
    Dim pFontDisp As IFontDisp
    Dim pRGB As IRgbColor
    Dim pSym As ITextSymbol
    Dim pFTextSym As IFormattedTextSymbol

    Set pFontDisp = New StdFont
    pFontDisp.Bold = True
    pFontDisp.Italic = True
    pFontDisp.Name = "Georgia"
    pFontDisp.Size = 24
    Set pRGB = New RgbColor
    pRGB.Red = 255
    pRGB.Blue = 200
    pRGB.Green = 200
    Set pSym = New TextSymbol
    Set pFTextSym = pSym
    pSym.Font = pFontDisp
    pSym.Color = pRGB

    pGraphicsContainer.Reset
    Set pElement = pGraphicsContainer.Next

    While Not pElement Is Nothing
    If TypeOf pElement Is ITextElement Then
    Set pTextElement = pElement
    pTextElement.Symbol = pSym
    End If
    Set pElement = pGraphicsContainer.Next
    Wend

    pMxDoc.ActiveView.Refresh

    End Sub


  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000006701

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic