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.
Yet, when using a macro to retrieve the position of that same shape, it displays the value 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.
Do you know the fastest way to learn foreign languages? It is to read, write, speak, and think in that language as often as possible. Apart from speaking, programming languages are no different. The more you immerse yourself in that language, the faster you will pick it up.
Therefore, what most people like you need is lots of examples that you can practice. That is why the 100 Excel VBA Macros eBook exists. It’s the book for all Excel users who want to learn how to read and write Excel macros, save time, and stand out from their peers. The book contains:
- 100 example codes to practice reading and writing macros that will embed the language into your thinking.
- An introduction to macros in Excel to ensure you can implement the VBA code in the book even if you have no prior knowledge.
- Consistent code layout between examples to enable you to understand the structure and easily customize the code to meet your needs.
- Downloadable workbook containing all the source code, so the examples can be added to your project to give you the benefit of VBA straight away.
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
Get our FREE VBA eBook of the 30 most useful Excel VBA macros.
Automate Excel so that you can save time and stop doing the jobs a trained monkey could do.
By entering your email address you agree to receive emails from Excel Off The Grid. We’ll respect your privacy and you can unsubscribe at any time.
If you’ve found this post useful, or if you have a better approach, then please leave a comment below.
Do you need help adapting this to your needs?
I’m guessing the examples in this post didn’t exactly meet your situation. We all use Excel differently, so it’s impossible to write a post that will meet everybody’s needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site) you should be able to adapt it to your needs.
But, if you’re still struggling you should:
- Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
- Ask the ‘Excel Ninja’ in your office. It’s amazing what things other people know.
- Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it’s clear and concise. List all the things you’ve tried, and provide screenshots, code segments and example workbooks.
- Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.
Don’t go yet, there is plenty more to learn on Excel Off The Grid. Check out the latest posts: