How to Move, Resize, and Recolor Shapes using Word VBA
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.

- 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).
Ensure that the Developer tab is enabled in your Word ribbon and that you have basic familiarity with writing macros in the VBA Editor.
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.
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.
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.
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.

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. Open the Developer Tab: Launch WPS Writer, open your document, and navigate to the Developer tab on the top ribbon.
- 2. Launch the VBA Editor: Click on 'Visual Basic' or press Alt+F11 to open the VBA Editor interface.
- 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. Run the Macro: Place your cursor at the desired location in your document and run the macro to dynamically insert the formatted shape.

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.




