VBA: Convert centimeters, inches & pixels to points

It is frustrating that Excel, PowerPoint and Word work natively using a measurement known as points.  However, measurements within the standard application menus are set in centimeters or inches.  This can be seen when setting the position and size of a shape in PowerPoint through the standard menus.

PowerPoint measures in Cms
Measurements in standard menus are in Centimeters

Yet, when using a macro to retrieve the position of that same shape, it displays the value in points.

PowerPoint measures in Points
Measurements for VBA are in Points

Below is the PowerPoint VBA Code to show the dimensions of the active shape:

Sub getShapeSizes()

Dim msgText As String
msgText = "Top: " & ActiveWindow.Selection.ShapeRange.Top & vbNewLine
msgText = msgText & "Left: " & ActiveWindow.Selection.ShapeRange.Left & vbNewLine
msgText = msgText & "Height: " & ActiveWindow.Selection.ShapeRange.Height & vbNewLine
msgText = msgText & "Width: " & ActiveWindow.Selection.ShapeRange.Width & vbNewLine

MsgBox msgText

End Sub

Whether the displayed measurements are in centimeters or inches is set through the Control Panel for PowerPoint.  For Excel, the default is also set through the Control panel, but this can be changed to be non-default within the Excel options. File -> Options -> Advanced -> Display -> Ruler Units.

Change Excel Unit of Measure

Converting from Inches or Centimeters to Points

Converting from inches or centimeters into points is reasonably straightforward, as there are 72 points to an inch or 28.35 points to a centimeter (rounded to 2 decimal places).  Microsoft has provided two useful VBA function to make this conversion

Convert from Inches to Points

Dim valueInches As Double
Dim valuePoints As Double
valueInches = 25
valuePoints = Application.InchesToPoints(valueInches)
Debug.Print valuePoints

Convert from Centimeters to Points

Dim valueCentimeters As Double
Dim valuePoints As Double
valueCentimeters = 25
valuePoints = Application.CentimetersToPoints(valueCentimeters)
Debug.Print valuePoints

Convert from Points to Centimeters

Dim valuePoints As Double
Dim valueCentimeters As Double
valuePoints = 50
valueCentimeters = valuePoints / Application.CentimetersToPoints(1)
Debug.Print valueCentimeters

Convert from Points to Inches

Dim valuePoints As Double
Dim valueInches As Double
valuePoints = 700
valueInches = valuePoints / Application.InchesToPoints(1)
Debug.Print valueInches

Converting from Points to Pixels

What about Pixels?  Whilst Pixels may seem to be an understandable unit of measure for the purposes of controlling positions of objects, it’s not as useful as you might expect.

The number of pixels will depend on a variety of factors, such as screen resolution used for each monitor.  However, if you are desperate to convert points to pixels the following VBA code could be used.

Dim valuePoints As Long
Dim valuePixels As Long
valuePoints = 500
valuePixels = Application.ActiveWindow.PointsToScreenPixelsX(valuePoints)
Debug.Print "X axis Pixels: " & valuePixels
valuePixels = Application.ActiveWindow.PointsToScreenPixelsY(valuePoints)
Debug.Print "Y axis Pixels: " & valuePixels

Discover how you can automate your work with our Excel courses and tools.

Excel Academy

Excel Academy
The complete program for saving time by automating Excel.

Excel Automation Secrets

Excel Automation Secrets
Discover the 7-step framework for automating Excel.

Office Scripts Course

Office Scripts: Automate Excel Everywhere
Start using Office Scripts and Power Automate to automate Excel in new ways.

3 thoughts on “VBA: Convert centimeters, inches & pixels to points”

  1. It’s very good to know this both functions: Application.ActiveWindow.PointsToScreenPixelsX and
    Application.ActiveWindow.PointsToScreenPixelsX

    Is there a list of the character length in points? Lower and Upper case ?

    I would be glad. I would be able to count the position of the strings on the screen. If I want to position them for example centralised, or I want to create a “table” from strings. That means they should begin under each other on the same position.

    Reply
    • I’m not aware of any list of character sizes. Each font will have different sizes of characters, so it would be difficult (unless you’re using a monospaced font like Courier, which are all the same size). Plus there are settings such size and bold/italic, which would also change the character size.

      Reply
  2. Hi,

    My question is very simple.
    Is there a way to determine for Powerpoint 2016 Prof (or for any Powerpoint version) the default unit set, using VBA code? i.e. Whether it is cms or inches or milimeters?

    JFYI, there is no such Ruler units dropdown in Powerpoint Options.

    Reply

Leave a Comment