How To: Set a reference scale for a text element on a map with ArcObjects


Instructions provided describe how to set a reference scale for text elements on a map with 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'
  3. Right-click the UIButtonControl, while the Customize dialog box is open and select View Source.
  4. Copy this code into the UIButtonControl's click event.
    Sub TextElemRefScale()
        Dim pDoc As IMxDocument
        Dim pContainer As IGraphicsContainer
        Dim pElement As IElement
        Dim pTextElement As ITextElement
        Dim pActiveView As IActiveView
        Set pDoc = ThisDocument
        Set pActiveView = pDoc.ActiveView
        Set pContainer = pActiveView
        'Loop through the graphics container
        'and find text element
        Set pElement = pContainer.Next
        While Not pElement Is Nothing
            'Get the specific text element
            If TypeOf pElement Is ITextElement Then
               Set pTextElement = pElement
               If pTextElement.Text = "oregon" Then  'specify the text of your text element
                    Dim pElemProp As IElementProperties3
                    Set pElemProp = pTextElement
                    pElemProp.ReferenceScale = 15000000  'change this to the desired reference scale
                End If
            End If
            Set pElement = pContainer.Next
        'refresh only the graphics, which includes text elements
        pDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
    End Sub