logo
search
Document Editing Problems

How to Resize Only Oversized Images in Word Using VBA

Maira MehtabMaira Mehtab Sep 27, 2026 869 views

Question details

The user needs to programmatically reduce the size of large inline pictures in a Word document that exceed a specific width limit, without affecting the size of smaller images.

Product
Microsoft Word
Device & OS
not provided
Scenario
Formatting a document containing multiple images of varying sizes where oversized figures disrupt the layout, requiring bulk standardization based on a width threshold.
Observed behavior
Manual resizing is inefficient. The desired outcome is a script that loops through the document, identifies pictures, checks if their width exceeds a set limit (e.g., 9.7 cm), and resizes them while preserving the original aspect ratio.
Before you start

Ensure the Developer tab is enabled in your Word ribbon to access the Visual Basic Editor, and verify whether the oversized images in your document are inserted as 'Inline with Text' or as floating objects.

Solution 1Recommended

Use a VBA Macro to Shrink Oversized Inline Pictures

This method uses a VBA script to iterate through all InlineShapes in the active document, identifying oversized pictures and reducing their width to 9.7 centimeters while locking the aspect ratio.

By default, Word places inserted images as 'Inline with Text'. This VBA script specifically targets the InlineShapes collection. If your document contains floating images (images with text wrapping styles like Square or Tight), they are classified as Shape objects and will not be affected by this macro.

You can also optionally modify the macro to center the images automatically after resizing them.

1
Open the VBA Editor

Open your Word document and press the 'Alt + F11' keys simultaneously to launch the Microsoft Visual Basic for Applications window.

2
Insert a New Module

In the VBA Editor, click on 'Insert' in the top menu bar, and then select 'Module' to create a blank workspace for your code.

3
Paste the Macro Code

Copy and paste the following code into the module window: Sub ShrinkFigures() Dim i As Long With ActiveDocument For i = 1 To .InlineShapes.Count With .InlineShapes(i) If .Type = wdInlineShapePicture Then If .Width > CentimetersToPoints(9.7) Then .LockAspectRatio = msoTrue .Width = CentimetersToPoints(9.7) End If End If End With Next i End With End Sub

4
Add Centering Alignment (Optional)

If you want the resized images to be centered horizontally on the page, add the line '.Range.Paragraphs(1).Alignment = wdAlignParagraphCenter' immediately after the second 'End If' statement in the macro.

5
Run the Macro

Click anywhere inside the macro code and press 'F5', or click the green 'Run' button in the toolbar, to execute the script and resize your oversized images.

Customizing the Width Limit: You can easily adjust the threshold by replacing '9.7' in the 'CentimetersToPoints(9.7)' function with your preferred maximum width value.
Advanced Document Formatting

Batch Resize Images Easily in WPS Writer

WPS Office Writer offers extensive support for document automation and advanced image formatting. You can seamlessly manage complex layouts, adjust picture sizes, and run VBA scripts in a fast and user-friendly environment.

  1. 1. Open Your Document: Launch WPS Writer and open the document containing the images you want to resize.
  2. 2. Access the Macro Editor: Press 'Alt + F11' to open the WPS Macro Editor (ensure the VBA extension is enabled in your version).
  3. 3. Apply the Resize Logic: Insert a new module, paste your VBA script targeting the InlineShapes collection, and adjust the threshold size if needed.
  4. 4. Execute the Code: Run the macro to instantly standardize the oversized images across your entire WPS document.
Fully compatible with Microsoft Word document formats (.docx) and VBA scripts.Handles heavy documents containing hundreds of oversized images smoothly.Features an intuitive user interface with built-in batch image compression and adjustment tools.Lightweight and free to use for your everyday document editing and formatting needs.
QA img-9

Frequently Asked Questions

Why are some images not being resized by the macro?

The provided macro only targets inline pictures (InlineShapes). If an image has a text wrapping style applied, such as 'Square', 'Tight', or 'Behind Text', it is considered a floating Shape object and will be ignored by this specific loop.

How do I resize floating shapes instead of inline shapes?

To resize floating images, you need to loop through the 'ActiveDocument.Shapes' collection rather than 'InlineShapes'. You must also add a condition to check if '.Type = msoPicture' before executing the resizing logic.

How can I change the VBA measurement unit from centimeters to inches?

Instead of using the 'CentimetersToPoints()' function, you can use the 'InchesToPoints()' function. For example, replacing 'CentimetersToPoints(9.7)' with 'InchesToPoints(3.5)' will set the maximum width limit to 3.5 inches.