Link to home
Start Free TrialLog in
Avatar of DrTribos
DrTribosFlag for Australia

asked on

Can I use VBA to apply corner radius on text box?

Hi All

I have a textbox with a table in it (not sure if that it a terrible idea, but it seems to be working) and I would like to apply rounded corners to the text box such that a specific radius is maintained...

I tried to record a macro to see what happens... but this is all I got:

  ActiveDocument.Shapes.Range(Array("Rounded Rectangle 5")).Select

(changing the corner was not recorded, grr)

help on this much appreciated.

Oh BTW - if this is a terrible idea (I'm using cross references and headings in my table & textbox) please let me know...

Cheers, S
Avatar of Rgonzo1971


Please refer to

Public Sub AddRoundRect()
    Dim sht As Worksheet
    Dim rect As Shape
    Set sht = ActiveSheet
    Set rect = sht.Shapes.AddShape(msoShapeRoundedRectangle, 400, 110, 150, 75)
    With rect.TextFrame2
        .TextRange = "Some Text In Here"
        .VerticalAnchor = msoAnchorMiddle
        .TextRange.ParagraphFormat.Alignment = msoAlignCenter
    End With
End Sub

Open in new window

Hi Steve,
This seems to work for me:
    Dim tb As Shape
    Set tb = ActiveDocument.Shapes(1)
   tb.AutoShapeType = msoShapeRoundedRectangle

Open in new window

Avatar of DrTribos


Hi Rgonzo1971 & Graham

Thanks for the code.  As far as I can tell the parameters that can be passed to msoShapeRoundedRectangle are to position the shape on the page and do not specify the radius...

The problem for me is that the text box resizes as text is entered / removed and the radii on the corners changes...  I'd rather my (my users) radii to remain constant... (I have a similar problem with callouts... the tail changes size with the textbox... most annoying).

I tested msoShapeRoundedRectangle after dragging the shape around a bit and it does indeed put the radii back to some default... but this depends on height & width :-(

Cheers, S
I don't think that there is any way to directly control the radii of the corners. They depend on the size of the shape, so that they stay in proportion.
Hi Rgonzo -  I get an EE Unauthorized Access Error when I try to follow your link.  It says the question has not yet been closed...  

Thanks, S
Avatar of Rgonzo1971

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

I, for one, can thank you.

Previously, I couldn't find how to adjust the radius of the corners manually, so assumed that no such adjustment was possible. Your code prompted me to persevere.

The secret is to drag the yellow diamond shape near the top left of the selected shape. It is possible to do this while macro recording is on, so that the index in the Adjustments collection can be confirmed from the recorded code.

I hope that this information is in your article.
Hi Rgonzo - thank you!