centering textbox text in a chart shape via vba

I can create a textbox on my chart and use the formula statement to move a value into it.

How do I then cause that text to be centered both vertically and horizontally?

Or how do I format it before the formula statement?

Or do I use a different shape?
gofasteddieAsked:
Who is Participating?
 
byundtConnect With a Mentor Commented:
If you select the textbox, you will be able to use the center justification icons in the Alignment group for both vertical and horizontal formatting on the Home menu item.

The VBA for the above formatting is similar to that posted by HarryHYLee, but different on the horizontal centering step.
Sub ChartTextboxCentering()
    With ActiveSheet.ChartObjects(1).Chart.Shapes("TextBox 1").TextFrame2
        .VerticalAnchor = msoAnchorMiddle
        .TextRange.ParagraphFormat.Alignment = msoAlignCenter
    End With
End Sub

Open in new window

0
 
junholeeCommented:
add labels works i think.
0
 
Harry LeeConnect With a Mentor Commented:
Find out the textbox object name, and use code similar to the following code.

    ActiveChart.Shapes.Range(Array("TextBox 1")).Select
    With Selection.ShapeRange.TextFrame2
        .VerticalAnchor = msoAnchorMiddle
        .HorizontalAnchor = msoAnchorCenter
    End With

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.