Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Determining Picture Size in a Macro.

Determining Picture Size in a Macro

Written by Allen Wyatt (last updated July 26, 2021)
This tip applies to Word 97, 2000, 2002, and 2003


1

Word keeps quite a bit of information together about the images that you insert in your documents. This information is necessary so that Word knows how to size, position, and display images. If you want to find out more information about the images in your document, then you need to know something about how Word stores the information.

Images are stored as either of two types of graphic objects: regular shapes or inline shapes. Regular shapes are those that reside on the drawing layer, as opposed to inline shapes, which reside in the text layer. Both types of objects are stored with different object collections. Regular shapes are in the Shapes collection, and inline shapes are stored in the InlineShapes collection. To access information about the objects, you just need to use a little VBA.

The following VBA macro will work in Word 2000 (or later versions) to create a document that displays the size of all the graphics objects within a document, in both points and pixels:

Sub FigureInfo()
    Dim iShapeCount As Integer
    Dim iILShapeCount As Integer
    Dim DocThis As Document
    Dim J As Integer
    Dim sTemp As String

    Set DocThis = ActiveDocument
    Documents.Add

    iShapeCount = DocThis.Shapes.Count
    If iShapeCount > 0 Then
        Selection.TypeText Text:="Regular Shapes"
        Selection.TypeParagraph
    End If
    For J = 1 To iShapeCount
        Selection.TypeText Text:=DocThis.Shapes(J).Name
        Selection.TypeParagraph
        sTemp = "     Height (points): "
        sTemp = sTemp & DocThis.Shapes(J).Height
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Width (points): "
        sTemp = sTemp & DocThis.Shapes(J).Width
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Height (pixels): "
        sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Height, True)
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Width (pixels): "
        sTemp = sTemp & PointsToPixels(DocThis.Shapes(J).Width, False)
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        Selection.TypeParagraph
    Next J

    iILShapeCount = DocThis.InlineShapes.Count
    If iILShapeCount > 0 Then
        Selection.TypeText Text:="Inline Shapes"
        Selection.TypeParagraph
    End If
    For J = 1 To iILShapeCount
        Selection.TypeText Text:="Shape " & J
        Selection.TypeParagraph
        sTemp = "     Height (points): "
        sTemp = sTemp & DocThis.InlineShapes(J).Height
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Width (points): "
        sTemp = sTemp & DocThis.InlineShapes(J).Width
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Height (pixels): "
        sTemp = sTemp & PointsToPixels(DocThis.InlineShapes(J).Height, True)
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        sTemp = "     Width (pixels): "
        sTemp = sTemp & PointsToPixels(DocThis.InlineShapes(J).Width, False)
        Selection.TypeText Text:=sTemp
        Selection.TypeParagraph
        Selection.TypeParagraph
    Next J
End Sub

This macro doesn't work in Word 97 because Word 97 does not recognize the PointsToPixels statement. If you remove the lines that use this statement (or create your own PointsToPixels function), then the macro will work just fine under Word 97.

Note that the macro returns the names of regular shapes, but not the names of inline shapes. The reason for this is that Word doesn't maintain the names of inline shapes. When you insert a regular shape in your document (again, on the drawing layer), then Word assigns a name to the shape, such as Rectangle 2 or Oval 3.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (1497) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Determining Picture Size in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Fixing Macro Button Behavior in Protected Worksheets

When working with macro buttons, you may run into some bizarre behavior related to the macros without really ...

Discover More

Specifying a Delimiter when Saving a CSV File in a Macro

You can, within a macro, save a workbook in several different file formats that are understood by Excel. However, you may ...

Discover More

Editing PivotTables without Underlying Data

If you ever try to edit a PivotTable and get an error that tells you that the "underlying data was not included," it can ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Disappearing Graphics Groups

Grouping graphics together can be a great way to manage them easier. Doing the grouping, however, could have unintended ...

Discover More

Moving Object Anchors

When you insert an object into your document, it is anchored to a paragraph. If you want to change the paragraph to which ...

Discover More

Selecting a Graphic Behind a Text Box

How to select a graphic that is obscured by a text box can be perplexing. Here's an overview of the different ways you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

2018-10-19 05:00:03

Tom Mukaiw

I hope you can help me. I am reading a word document from top to bottom and I need to know when I have come upon a picture, copy it and paste it into another document. How do I know this so that I can paste it into the correct place in the other document?


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.