Word VBA, Picture Dimensions

In this article I will explain how you can use VBA for word to get the dimensions of a picture in a word document.

The first step is to determine whether the picture is an inline or floating. For more information on this topic please see the link below:

The next step would be to determine the index of the pictures shape container. I have covered this in the article below:


Picture Height:

In points:

The picture height can be obtained in “points” for floating shapes using the code below:

intHeight = Shapes.Item(1).Height

and for inline shapes:

intHeight = InlineShapes.Item(1).Height

Note: In the examples above it is assumed the shape has an index of “1”.

In Pixels:

There is no direct function that will return the picture height in pixels, therefore we would need to convert the values obtained from the previous example to pixels. The relationship between pixels and points can be seen below:

1 Pixel = 72/96*1 Point

Therefore the height of a shape can be obtained in pixels from the code below:

intHeight = Shapes.Item(1).Height*72/96

and for inline shapes:

intHeight = InlineShapes.Item(1).Height*72/96


Picture Width:

In points:

The picture width can be obtained in “points” for floating shapes using the code below:

intWidth = Shapes.Item(1).Width

and for inline shapes:

intWidth = InlineShapes.Item(1).Width

Note: In the examples above it is assumed the shape has an index of “1”.

In Pixels:

Similar to what was explained in the previous section there is no direct function that will return the picture height in pixels, therefore we would need to convert the values obtained from the previous example to pixels. The relationship between pixels and points can be seen below:

1 Pixel = 72/96*1 Point

Therefore the height of a shape can be obtained in pixels from the code below:

intWidth = Shapes.Item(1).Height*72/96

and for inline shapes:

intWidth = InlineShapes.Item(1).Height*72/96

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website  www.software-solutions-online.com

Leave a Reply

Your email address will not be published. Required fields are marked *