How to Use a Word VBA Macro to Paste Floating Shapes at the Cursor
Question details
The user needs a VBA macro solution to precisely paste floating shapes or images exactly at the current cursor location to prevent them from shifting away from their anchors.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Pasting floating images or shapes into a document where strict positioning relative to the text cursor (character and line) is required.
- Observed behavior
- When pasting floating objects in Word, they frequently appear far from their text anchors or even outside the visible page area, requiring manual realignment.
Ensure that the Developer tab is enabled in your Word ribbon to access the VBA editor, and make sure you have already copied a shape or image to your clipboard.
Create and Run a Custom VBA Macro
Use a VBA script to automatically paste the clipboard contents, target the shape range, and set its horizontal and vertical alignment directly to the cursor's character and line.
This macro utilizes the Selection.Paste method and immediately adjusts the Selection.ShapeRange object. By setting the RelativeHorizontalPosition to the character and the RelativeVerticalPosition to the line, the shape is forced to stay exactly where the cursor was placed.
Press 'Alt + F11' on your keyboard while Microsoft Word is open to launch the Visual Basic for Applications (VBA) editor.
In the VBA editor, click on 'Insert' in the top menu bar and select 'Module' to create a new blank script window.
Type or paste the VBA code into the module. Start with 'Sub FloatingPasteAndSetPosition()', then use 'Selection.Paste'. Add a With block for 'Selection.ShapeRange' setting '.RelativeHorizontalPosition = wdRelativeHorizontalPositionCharacter', '.RelativeVerticalPosition = wdRelativeVerticalPositionLine', '.Left = InchesToPoints(-0.2)', and '.LockAnchor = True'.
Place your cursor at the exact text location in your document where you want the shape. Ensure a shape is copied to your clipboard, press 'Alt + F8', select 'FloatingPasteAndSetPosition', and click 'Run'.
Easily Manage Document Layouts and Shapes with WPS Office
While complex VBA macros are sometimes required in Word for precise object placement, WPS Writer offers highly intuitive layout tools for floating shapes without the need for custom coding. Experience a lightweight, free alternative that makes managing document graphics incredibly simple.

Frequently Asked Questions
Why do my pasted images in Word jump to the wrong page?
By default, Word may insert images inline or anchor floating images to the nearest paragraph. If the paragraph text shifts, or if the relative positioning is set to the page margin instead of the specific text line, the image will appear detached from the location where your cursor originally was.
How do I manually lock an image anchor without using VBA?
Select the inserted image, click the 'Layout Options' icon floating next to it, choose 'See more...', navigate to the 'Position' tab, and check the 'Lock anchor' box at the bottom of the dialog window.
Can I assign a keyboard shortcut to this VBA macro for faster pasting?
Yes. Go to 'File' > 'Options' > 'Customize Ribbon', and click the 'Customize' button next to Keyboard shortcuts. Select 'Macros' in the Categories list, choose your custom floating paste macro, and assign a preferred key combination like 'Ctrl + Shift + V'.
What does 'wdRelativeHorizontalPositionCharacter' do in the code?
It is a VBA enumeration that tells the word processor to calculate the shape's horizontal offset starting exactly from the specific text character where the anchor is placed, rather than measuring from the column, margin, or page edge.




