VBA to Center Text in a Shape

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I would appreciate any help...

I have a macro that creates a shape and then lets me format it. For example, this part of the code allows me to bold the text:

With MyShape.TextFrame
.Characters.Font.Bold = False
End With

What I would also like to do is to middle center the text in the shape. I did some research and tried adding the following two lines into the With/End With loop, but get an error:

.HorizontalAnchor = msoAnchorCenter
.VerticalAnchor = msoAnchorTop

Can anyone help me on where I am going wrong?

Thanks,

Mike
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You need to use TextFrame2 for that
VBA Code:
    With myshape.TextFrame2
      .VerticalAnchor = msoAnchorMiddle
      .HorizontalAnchor = msoAnchorCenter
    End With
 
Upvote 0
You need to use TextFrame2 for that
VBA Code:
    With myshape.TextFrame2
      .VerticalAnchor = msoAnchorMiddle
      .HorizontalAnchor = msoAnchorCenter
    End With
Thanks! Appreciate it.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,226,739
Messages
6,192,739
Members
453,754
Latest member
milestogo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top