VBA & Macro Problems

How to Move, Resize, and Recolor Shapes using Word VBA

Nimra MalikNimra Malik Nov 4, 2026 872 views

Question details

The user needs to learn which VBA parameters control the insertion of a rectangle shape near the cursor, specifically adjusting its position, dimensions, and outline color.

How to Move, Resize, and Recolor Shapes using Word VBA
Product
Word
Device & OS
not provided
Scenario
Writing a VBA macro to dynamically insert and format a shape relative to the current cursor position.
Observed behavior
The user wants to achieve specific shape positioning (below and to the left of the cursor), precise width/height adjustments, and a specific outline color (white).
Before you start

Ensure that the Developer tab is enabled in your Word ribbon and that you have basic familiarity with writing macros in the VBA Editor.

Solution 1Recommended

Use VBA Properties to Position, Size, and Color the Shape

Modify the VBA parameters to accurately position the shape relative to the cursor, adjust its dimensions, and apply RGB colors to the outline.

In Word VBA, controlling a shape requires manipulating specific properties of the Shape object. By calculating the current cursor coordinates, you can offset the shape's insertion point dynamically. Once inserted, the shape's dimensions and line colors can be modified directly.

1
Calculate the cursor position

Use the Selection.Characters object to find the cursor's coordinates. Define your vertical position using '.First.Information(wdVerticalPositionRelativeToPage) + 12' and the horizontal position using '.First.Information(wdHorizontalPositionRelativeToPage) - 12' to move the shape down and to the left.

2
Set the shape dimensions

When calling the AddShape method, or adjusting an existing shape object, input your preferred numerical values into the Width and Height properties to resize the rectangle.

3
Change the outline color

Target the shape's Line object to change its border. Replace the default theme color setting with '.ForeColor.RGB = RGB(255, 255, 255)' to force the outline color to absolute white.

Use VBA Properties to Position, Size, and Color the Shape
Measurement Units: The offset values like +12 and -12 in the positioning code represent points. You can increase or decrease these numeric offsets until the placement perfectly fits your layout.
Efficient Word Processing with WPS Writer

Create and Run Macros Easily in WPS Writer

WPS Office offers comprehensive VBA macro support, allowing you to easily automate tasks like inserting and formatting shapes just as you would in Microsoft Word.

  1. 1. Open the Developer Tab: Launch WPS Writer, open your document, and navigate to the Developer tab on the top ribbon.
  2. 2. Launch the VBA Editor: Click on 'Visual Basic' or press Alt+F11 to open the VBA Editor interface.
  3. 3. Insert the Macro Code: Insert a new Module from the menu and paste your VBA code for positioning, sizing, and coloring the shape.
  4. 4. Run the Macro: Place your cursor at the desired location in your document and run the macro to dynamically insert the formatted shape.
Full support for VBA macros and automated scriptingHighly compatible with Microsoft Word document formats (.docx, .docm)Lightweight, fast execution of complex formatting tasksIntuitive Developer tab for easy macro management
microsoft office alternative - wps office

Frequently Asked Questions

How do I make the shape outline transparent instead of white in VBA?

To remove the border completely, set the '.Visible' property of the shape's Line object to 'msoFalse' (for example, 'Shape.Line.Visible = msoFalse').

What unit of measurement does Word VBA use for shape sizes?

Word VBA uses points (pt) as the default unit of measurement for shape widths, heights, and positional offsets. One inch is equal to 72 points.

Why does my shape appear on the wrong page when using cursor position?

This happens if the positional anchor is incorrectly referenced. Ensure you are using 'wdVerticalPositionRelativeToPage' and verify that the cursor (Selection) is exactly where you expect before the macro executes.