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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

add labels works i think.
Harry LeeCommented:
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

byundtMechanical EngineerCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.