logo
search
Formatting Issues

How to Set Image Position, Size, and Text Wrapping in Word VBA

Khadija KhanKhadija Khan Oct 21, 2026 869 views

Question details

The user needs to batch adjust the position, dimensions, and text wrapping of multiple images in a Word document using a VBA macro.

How to Set Image Position, Size, and Text Wrapping with Word VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Automating document formatting to standardize the layout of numerous images, specifically setting exact dimensions and applying top-and-bottom text wrapping.
Observed behavior
The macro fails or produces an error when trying to position images. This occurs because the images are formatted as 'InlineShape' objects, which act like standard text characters and do not support independent page coordinates or wrapping.
Before you start

Create a duplicate copy of your document before running any new VBA macros to ensure you can easily revert if the automated batch formatting produces an unexpected layout.

Solution 1Recommended

Convert InlineShapes to Shapes to Apply VBA Formatting

Use this solution if your images are currently inserted in line with text. Converting them to floating Shape objects enables independent positioning and wrapping.

Inline shapes act as characters within a text string, making it impossible to assign them specific page coordinates or text wrapping. To fix this, your VBA code must first convert the InlineShape to a floating Shape before applying the position, size, and wrap settings.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications editor. Go to Insert > Module to create a new blank script.

2
Write the conversion loop

Create a 'Sub' procedure and use a 'For Each' loop to iterate through the 'ActiveDocument.InlineShapes' collection. Inside the loop, use the 'ConvertToShape' method to change the image into a floating object.

3
Apply dimensions and wrap formatting

Assign the converted shape to a variable. Use the 'InchesToPoints' function to set specific '.Height', '.Width', and '.Left' values. Finally, set '.WrapFormat.Type' to 'wdWrapTopBottom'.

4
Run the macro

Press F5 or click the Run button to execute the script. The macro will automatically convert and format every inline image in your document.

Convert InlineShapes to Shapes to Apply VBA Formatting
VBA Variable Definition: Ensure you properly declare your variables, such as 'Dim objShape As Shape', to avoid runtime errors during the conversion process.
Efficient Document Formatting

Batch Format Images Automatically in WPS Writer

WPS Office Writer offers advanced document processing capabilities, including full support for VBA macros. You can execute standard Microsoft Word VBA scripts directly within WPS to automate repetitive formatting tasks, like resizing and repositioning dozens of images instantly.

  1. 1. Open your document in WPS: Launch WPS Writer and open the document containing the images you wish to format.
  2. 2. Access the Macros menu: Navigate to the Tools tab on the top ribbon and click on Macros to access the VBA environment.
  3. 3. Paste your VBA script: Select the VBA Editor, insert a new module, and paste your shape conversion and dimension-setting script.
  4. 4. Execute the formatting: Click Run. WPS Writer will natively process the VBA commands, resizing and wrapping all images according to your parameters.
Seamless compatibility with Microsoft Word document macro formats (.docm, .docx).Built-in VBA editor lets you run and edit image formatting scripts effortlessly.Lightweight architecture ensures documents with heavy graphics load rapidly.Highly intuitive interface making advanced document automation accessible.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a VBA error when trying to resize InlineShapes?

InlineShapes act like characters within a sentence rather than independent visual objects. They do not have properties for absolute page coordinates or text wrapping. You must use the 'ConvertToShape' method in VBA first before assigning position values.

What is the VBA command for Top and Bottom text wrapping?

To apply Top and Bottom text wrapping to a floating shape via VBA, you need to set the WrapFormat.Type property to the constant 'wdWrapTopBottom'.

Can I convert an inline shape to a floating shape manually without macros?

Yes. Right-click the image in your document, hover over 'Wrap Text', and select any wrapping style other than 'In Line with Text' (such as 'Top and Bottom' or 'Square'). This instantly converts it to a floating shape.

How do I ignore the aspect ratio when setting image size in VBA?

To stretch or compress an image to exact dimensions regardless of its original proportions, add '.LockAspectRatio = msoFalse' to your VBA script before defining the new '.Height' and '.Width' values.