How to Convert Wrapped Images to Inline Images Using Word VBA Macro
Question details
The user needs to automate the process of converting document images with Top and Bottom text wrapping to In Line with Text wrapping using VBA macros.

- Product
- Word
- Device & OS
- not provided
- Scenario
- A document contains multiple images formatted with Top and Bottom text wrapping. The user wants to review and convert them to inline shapes in bulk, or quickly convert a single selected image using a keyboard shortcut.
- Observed behavior
- Manually changing the layout option for each image individually is time-consuming. An automated script is required to iterate through the shapes and apply the conversion without skipping images.
Ensure that the Developer tab is enabled in your Word ribbon to access the VBA editor. It is highly recommended to save a backup copy of your document before running any macro that modifies document elements.
Use a VBA Macro to Review and Convert All Images
This solution iterates through all images in your document from the last to the first, prompting you to convert each 'Top and Bottom' wrapped image to an inline shape.
Because of how Word VBA handles collections, converting a shape removes it from the Shapes collection and shifts the index of remaining shapes. To prevent skipping any images, this macro processes shapes in reverse order (from the end of the document to the beginning).
It will specifically look for images with 'Top and Bottom' wrapping. For each image, it scrolls to its location and asks if you want to convert it.
Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications (VBA) editor.
In the Project Explorer pane on the left, right-click your document name, select Insert, and then click Module.
Copy and paste the following code into the module window: Sub SetPixInline() Dim oshape As Shape Dim nCount As Long Dim rsp As VbMsgBoxResult For nCount = ActiveDocument.Shapes.Count To 1 Step -1 Set oshape = ActiveDocument.Shapes(nCount) With oshape If .WrapFormat.Type = wdWrapTopBottom Then .Select ActiveWindow.ScrollIntoView oshape rsp = MsgBox("Change to inline?", vbYesNoCancel, "Change wrapping") If rsp = vbCancel Then Exit Sub ElseIf rsp = vbYes Then .ConvertToInlineShape End If End If End With Next nCount End Sub
Close the VBA editor. Press Alt + F8 to open the Macros dialog, select SetPixInline, and click Run. Choose Yes, No, or Cancel for each detected image.

Use a VBA Macro to Convert a Single Selected Image
If you prefer to manually select which image to convert without confirmation prompts, this shorter macro will instantly change the currently selected image to In Line with Text.
Automate Image Wrapping Conversions with WPS Writer
WPS Office provides robust document processing capabilities with full support for Microsoft Word macros. You can seamlessly run your VBA scripts to manage image formatting while enjoying a lightweight and highly efficient office suite.
- 1. Open Your Document in WPS Writer: Launch WPS Office, open the Writer application, and load your document containing the wrapped images.
- 2. Access the Developer Tools: Navigate to the Developer tab on the top ribbon. If it is not visible, go to Settings to enable the Developer tools.
- 3. Create a New Macro: Click on 'Macros', type a name for your macro (e.g., SetPixInline), and click 'Create' to open the VBA editor.
- 4. Paste and Execute: Paste the provided VBA script into the editor, save it, and run the macro directly from the WPS ribbon to convert your images.

Frequently Asked Questions
Why does the macro process images from the last to the first?
Word uses separate collections for standard Shapes (wrapped images) and InlineShapes. When a shape is converted to inline, it is removed from the Shapes collection. This dynamically changes the index numbers of all subsequent shapes. Processing them in reverse order (from highest index to 1) ensures that the changing indexes do not cause the loop to skip any images.
How do I assign a keyboard shortcut to my new macro?
Go to File > Options > Customize Ribbon. Click the 'Customize' button next to 'Keyboard shortcuts' at the bottom. In the Categories list, scroll down and select 'Macros'. Select your macro on the right, click inside the 'Press new shortcut key' box, press your desired key combination, and click 'Assign'.
Can I modify the macro to target images with 'Square' or 'Tight' text wrapping?
Yes. In the VBA code, look for the line 'If .WrapFormat.Type = wdWrapTopBottom Then'. You can change the constant 'wdWrapTopBottom' to 'wdWrapSquare', 'wdWrapTight', or 'wdWrapThrough' depending on which wrapping style you want the macro to target.




