logo
search
VBA & Macro Problems

How to Convert Wrapped Images to Inline Images Using Word VBA Macro

Nimra MalikNimra Malik Sep 28, 2026 869 views

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.

How to Convert Wrapped Images to Inline Images Using Word VBA Macro
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 on your keyboard to open the Microsoft Visual Basic for Applications (VBA) editor.

2
Insert a New Module

In the Project Explorer pane on the left, right-click your document name, select Insert, and then click Module.

3
Paste the Macro Code

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

4
Run the Macro

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 Review and Convert All Images
Assign a Shortcut: You can assign this macro to a keyboard shortcut or the Quick Access Toolbar via File > Options > Customize Ribbon for faster access in the future.
Advanced Document Automation

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. 1. Open Your Document in WPS Writer: Launch WPS Office, open the Writer application, and load your document containing the wrapped images.
  2. 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. 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. 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.
Fully compatible with Microsoft Word (.docx) formats and VBA macro scripts (.docm).Advanced Developer tools for automating repetitive image layout adjustments.Free to download with a lightweight installation and familiar user interface.
microsoft office alternative - wps office

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.