Count Images in Word Document: 4 Ways
In this article
- Why Counting Images in Word Is Tricky
- Method 1: Find and Replace (Counts Inline Images Only)
- Method 2: VBA Macro (Counts All Images)
- Method 3: Refined VBA for Pictures Only
- Method 4: Save as HTML and Count Files
- Common Problems and Misconceptions
- How to Count Images in a Selection or Specific Section
- Frequently Asked Questions
To count images in a Word document, you can use the built-in Find and Replace feature to count inline images, or use a simple VBA macro to count all images (including floating ones). This article explains four methods, from the quickest manual approach to a script that gives you a precise total.
in t | Finish time | min | 50 | 0 in d | Distance | km | 10 | 0 out pace | Average pace | min/km | t / d | 2 out speed | Average speed | km/h | d / (t / 60) | 2
Why Counting Images in Word Is Tricky
Word documents can contain images in two different states: inline (anchored to a line of text) and floating (positioned freely on the page). The Find and Replace method only counts inline images because it searches for the inline image marker. Floating images are anchored to a paragraph but are not part of the text flow, so they don't appear in a text search. This is why the simple method often gives a lower number than the actual total.
Method 1: Find and Replace (Counts Inline Images Only)
- Press Ctrl + H to open the Find and Replace dialog.
- Click in the Find what box and leave it empty.
- Click More > Special and choose Graphic (or type
^gmanually). - In the Replace with box, type the same
^g(or leave it empty). - Click Replace All. Word will show a message like "Word has completed its search… 12 items replaced." That number is your inline image count.
This method is fast and requires no coding, but it misses floating images. If you have a mix of inline and floating images, the total will be higher than the number shown.
Method 2: VBA Macro (Counts All Images)
For a complete count of every image, use a simple VBA macro. This works in Word 2010, 2013, 2016, 2019, 2021, and Microsoft 365.
- Press Alt + F11 to open the VBA editor.
- Click Insert > Module.
- Paste the following code:
Sub CountImages()
Dim imgCount As Long
imgCount = ActiveDocument.InlineShapes.Count + ActiveDocument.Shapes.Count
MsgBox "Total images: " & imgCount
End Sub
- Press F5 to run the macro. A message box shows the total.
This counts both inline shapes (InlineShapes) and floating shapes (Shapes). Note that this counts all shapes, including text boxes, autoshapes, and charts. If you only want pictures, you need a more refined filter.
Method 3: Refined VBA for Pictures Only
If your document contains text boxes or drawn shapes that you don't want to count, use this version that filters for actual picture files:
Sub CountPicturesOnly()
Dim picCount As Long
Dim s As Shape
Dim ish As InlineShape
For Each ish In ActiveDocument.InlineShapes
If ish.Type = wdInlineShapePicture Then picCount = picCount + 1
Next ish
For Each s In ActiveDocument.Shapes
If s.Type = msoPicture Then picCount = picCount + 1
Next s
MsgBox "Pictures only: " & picCount
End Sub
This counts only embedded pictures (JPEG, PNG, etc.), not text boxes or shapes.
Method 4: Save as HTML and Count Files
Another workaround is to save the document as an HTML file and then count the image files in the accompanying folder.
- Go to File > Save As and choose Web Page (*.htm; *.html).
- Save the file. Word creates a separate folder with the same name plus
_files. - Open that folder. Every image in the document is saved as a separate file (e.g., image001.png, image002.jpg).
- Count the files in the folder. This gives you the total number of image files, including floating ones.
This method is useful if you don't want to use VBA and you have a mix of image types. However, it may count some images that are not visible (like background images) and may not count images that are part of a drawing canvas.
Common Problems and Misconceptions
- Find and Replace returns 0 even though images exist – This happens when all images are floating. Use VBA method instead.
- VBA counts text boxes as images – The simple VBA method counts all shapes, including text boxes. Use the refined version if you need pictures only.
- Images in headers/footers are not counted – The VBA methods above count images in the main document body only. To include headers/footers, you need to loop through each header/footer separately.
- Linked images vs embedded – If images are linked (not embedded), they still appear as shapes and are counted, but the actual file is external.
How to Count Images in a Selection or Specific Section
If you only need to count images in a particular section or a selected range, you can modify the VBA code. For example, to count images in a selection, use Selection.InlineShapes.Count and Selection.Shapes.Count instead of ActiveDocument. To count images in a specific range (e.g., pages 2-4), you can set a Range object and iterate through it.
Frequently Asked Questions
Does the Find and Replace method count floating images?
No. The Find and Replace method searches for the inline image marker (^g) which only appears for inline images. Floating images are not part of the text stream, so they are not found. Use the VBA method to count all images.
Why does my VBA count include text boxes?
Because text boxes are considered shapes. The ActiveDocument.Shapes.Count property counts all shapes, including text boxes, autoshapes, and pictures. If you only want pictures, filter by type as shown in Method 3.
Can I count images in a Word document without opening it?
Yes, you can use a script or a third-party tool, but it's not built into Word. One simple approach is to unzip the .docx file (it's a ZIP archive) and count the files in the word/media folder. This folder contains all embedded images. This works for .docx files only, not older .doc files.
How do I count images in a Word document on Mac?
Word for Mac also supports VBA. Press Option + F11 to open the VBA editor and run the same macro. Alternatively, you can use the Find and Replace method (Cmd + H) with the same ^g special character.
Does the image count include images in headers and footers?
No, the standard VBA methods only count images in the main document body. To include headers/footers, you need to loop through each header/footer and add their counts. This is more advanced and requires additional code.
Why does the Find and Replace method sometimes replace images with nothing?
If you leave the Replace with box empty, Word will delete the images when you click Replace All. To avoid this, always type ^g in the Replace with box as well, so it replaces images with themselves. This way, nothing is deleted and you get the count.