Share via


Issue: Formatting individual characters of Data Labels of Charts programmatically in Excel 2007 SP2

If you are working with Charts programmatically in Excel 2007 Service Pack 2, and are trying to set the formatting of individual characters of Data Labels of charts programmatically, you will notice that the formatting gets applied to the whole of Data Label instead of the specific character/range.

Here is a snippet which one would typically be used to set formatting of specific characters:

 Sub Test()
    Dim ch As Chart
    Dim series As series
    Dim points As points
    Dim label As DataLabel
    Dim chars As Characters
    Dim font As font
    
    Set ch = ActiveSheet.Shapes(1).Chart
    
    Set series = ch.SeriesCollection(1)
    Set points = series.points
    Set label = points(1).DataLabel
    
    label.Text = label.Text & vbCrLf & "a"
    
    Set chars = label.Characters(3, 1)
    
    Set font = chars.font
    
    font.Size = 24
End Sub

The above code will work as desired (format individual characters) on Excel 2003 and Excel 2007 Service Pack 1 releases.

This behavior is a known bug with Excel 2007 Service Pack 2 release, and the Excel development team is looking into it. Unfortunately, there is no known programmatic workaround possible for this requirement. Character level formatting of Data labels can only be set manually as of now.