A client sent a design for a Word template that had lots of boxes and photos with uniform rounded corners. Not an unreasonable request, but Office doesn’t do that well. In PowerPoint, Word and Excel, rounded corners are proportional to the size of the shape. Making them uniform manually is picky and time-consuming. But with a dash of VBA, we can make the job easy.
Uniform Rounded Corners – Cool Code
The Math
As a round-cornered shape gets larger, the corner radius increases as well, in proportion to the length of the shortest side of the shape. Since we want to keep the radius the same size, we need to create a formula that makes a smaller number as the shorter side increases. We need an inverse number! We can create this by dividing the preferred corner radius by the short side size. And you thought you’d never need that high school math!
Here’s VBA code that will work in Excel, Word and PowerPoint on selected round-cornered boxes. Thanks to the Rembrandt Kuipers and Ernst Mathys who have commented below, this macro has been improved since it was originally published. Replace the number after sngRadius with your desired radius size in points.
Sub RoundedCornersFixedRadius() Dim oShape As Shape Dim sngRadius As Single sngRadius = 8.50394 'Radius size in points. 8.50394pt is equal to 3mm. For Each oShape In ActiveWindow.Selection.ShapeRange With oShape If .AutoShapeType = msoShapeRoundedRectangle Then LengthOfShortSide = IIf(.Width > .Height, .Height, .Width) .Adjustments(1) = sngRadius / LengthOfShortSide End If End With Next oShape End Sub
To set rounded corners on a PowerPoint placeholder, open Slide Master view, select the placeholder and run the above macro.
Uniform Rounded Corners for the Whole Document
To run this on a whole presentation, document or workbook, we need to customize the routine for each Office program. Here’s the Excel version:
Sub RoundAllXLCorners() Dim oWorksheet As Worksheet, oShape As Shape, sngRadius As Single sngRadius = 8.50394 'Radius size in points. For Each oWorksheet In ActiveWorkbook.Worksheets For Each oShape In oWorksheet.Shapes With oShape If .AutoShapeType = msoShapeRoundedRectangle Then LengthOfShortSide = IIf(.Width > .Height, .Height, .Width) .Adjustments(1) = sngRadius / LengthOfShortSide End If End With Next oShape Next oWorksheet End Sub
To do the same in PowerPoint
Sub RoundAllPPCorners() Dim oSlide As Slide, oShape As Shape, sngRadius As Single sngRadius = 8.50394 'Radius size in points. For Each oSlide In ActivePresentation.Slides For Each oShape In oSlide.Shapes With oShape If .AutoShapeType = msoShapeRoundedRectangle Then LengthOfShortSide = IIf(.Width > .Height, .Height, .Width) .Adjustments(1) = sngRadius / LengthOfShortSide End If End With Next oShape Next oSlide End Sub
And finally, for Word
Sub RoundAllWDCorners() Dim oShape As Shape, sngRadius As Single sngRadius = 8.50394 'Radius size in points. For Each oShape In ActiveDocument.Shapes With oShape If .AutoShapeType = msoShapeRoundedRectangle Then LengthOfShortSide = IIf(.Width > .Height, .Height, .Width) .Adjustments(1) = sngRadius / LengthOfShortSide End If End With Next oShape End Sub
The Word version is a little simpler because a Word document is one big object, while Excel and PowerPoint both have multiple objects for each worksheet and slide, respectively. But the similarites point out that when you’re searching online for VBA code, finding something for a different program and modifying it can be a huge time-saver. By far, Excel has way more code written for it, so Excel VBA sites can be a fruitful source for Word and PowerPoint code ideas.
These macros have been tested under both Windows and macOS and work well under both.
To use these macros with other shapes, please see my article Every AutoShape – Cool Code for a downloadable reference file showing all AutoShapes along with their XML and VBA names. Then replace msoShapeRoundedRectangle with the mso shape name you need.