How to Set Image Position, Size, and Text Wrapping in Word VBA
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.

- 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.
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.
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.
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.
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.
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'.
Press F5 or click the Run button to execute the script. The macro will automatically convert and format every inline image in your document.

Format Existing Floating Shapes Using the Shapes Collection
Apply exact sizing and positioning settings to all images that are already floating shapes without needing to convert them.
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. Open your document in WPS: Launch WPS Writer and open the document containing the images you wish to format.
- 2. Access the Macros menu: Navigate to the Tools tab on the top ribbon and click on Macros to access the VBA environment.
- 3. Paste your VBA script: Select the VBA Editor, insert a new module, and paste your shape conversion and dimension-setting script.
- 4. Execute the formatting: Click Run. WPS Writer will natively process the VBA commands, resizing and wrapping all images according to your parameters.

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.




