How to add a balloon callout


This sample code adds a balloon callout text element in the center of the current active view extent. Modify the code to change the position of the text element and callout anchor.

How to use

  1. Paste the code into VBA.
  2. Modify the text element string as desired.
  3. Run the macro.
[VBA]
Public Sub AddBalloonCallout()
    Dim pMxDoc As IMxDocument
    Dim pTextElement As ITextElement
    Dim pElement As IElement
    Dim pPoint As IPoint
    Dim pCallout As ICallout
    Dim pTextSymbol As IFormattedTextSymbol
    Dim pGraphicsContainer As IGraphicsContainer
    Dim midX As Double, midY As Double
    
    'Obtain a reference to the document
    Set pMxDoc = Application.Document
    
    'Create a new text element
    Set pTextElement = New TextElement
    Set pElement = pTextElement 'QI
    pTextElement.Text = "Text callout" & vbCrLf & "In the middle of the screen"
    
    'Position the new element on the active view's center point
    midX = (pMxDoc.ActiveView.Extent.XMax + pMxDoc.ActiveView.Extent.XMin) / 2
    midY = (pMxDoc.ActiveView.Extent.YMax + pMxDoc.ActiveView.Extent.YMin) / 2
    Set pPoint = New Point
    pPoint.PutCoords midX, midY
    pElement.Geometry = pPoint
    
    'Set the text element symbology to a default balloon callout
    Set pTextSymbol = New TextSymbol
    Set pCallout = New BalloonCallout
    Set pTextSymbol.Background = pCallout
    'Use this formula to get a callout anchor point location
    pPoint.PutCoords midX - pMxDoc.ActiveView.Extent.Width / 4, midY + pMxDoc.ActiveView.Extent.Width / 20
    pCallout.AnchorPoint = pPoint
    pTextElement.Symbol = pTextSymbol
    
    'Add the element to the active view, either the focus Map or PageLayout
    Set pGraphicsContainer = pMxDoc.ActiveView
    pGraphicsContainer.AddElement pElement, 0
    pElement.Activate pMxDoc.ActiveView.ScreenDisplay
    
    'Flag the area of the new element for refreshing
    pMxDoc.ActiveView.PartialRefresh esriViewGraphics, pElement, Nothing
    
End Sub