Formatting Issues

How to Set Microsoft Word Frame Width and Height to Automatic with VBA

Tauseeq MagsiTauseeq Magsi Oct 14, 2026 870 views

Question details

The user needs a VBA macro to automatically adjust the width and height of all frames in a Word document to prevent pasted text from being cut off.

How to Automatically Resize Microsoft Word Frames with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Pasting content from other software into Word documents places the text into horizontal frames with exact dimensions.
Observed behavior
The exact height and width settings of the frames cause the pasted text to be truncated. Previous macro attempts failed because they incorrectly targeted Shape objects instead of Frames.
Before you start

Before running any VBA macros, ensure you save a copy of your document to prevent accidental formatting changes, and verify that the Developer tab is enabled in your Word ribbon.

Solution 1Recommended

Use a VBA Macro to Set Frame Sizing Rules to Automatic

Run a simple VBA script that iterates through the Frames collection to adjust the sizing rules, fixing the truncated text.

Word frames are distinctly different from Shape text boxes. If your VBA code targets 'Shapes', it will miss the frames entirely.

Using the built-in 'Frames' collection ensures you apply the correct wdFrameAuto property to the right elements across the entire document.

1
Open the VBA Editor

Press Alt + F11 to open the VBA Editor in Microsoft Word.

2
Insert a New Module

Click Insert > Module from the top menu to create a new macro module.

3
Paste the VBA Code

Paste the following code: Sub ResizeFrames() For Each f In ActiveDocument.Frames: f.HeightRule = wdFrameAuto: f.WidthRule = wdFrameAuto: Next f End Sub

4
Run the Macro

Press F5 or click the Run button at the top of the editor. Close the VBA window and return to your document.

Use a VBA Macro to Set Frame Sizing Rules to Automatic
Macro Executed: All frames in your document will instantly switch to automatic sizing, revealing any previously cut-off pasted text.
Powerful VBA Support in WPS

Run Macros and Manage Frames Easily with WPS Writer

WPS Office provides robust VBA support, allowing you to run the exact same macro to resize frames automatically. It offers seamless compatibility with Microsoft Word documents, ensuring your formatting remains intact.

  1. 1. Install WPS Office: Download and install WPS Office, then open your .docx file in WPS Writer.
  2. 2. Access the Macros Tool: Navigate to the 'Tools' tab and ensure the VBA module is enabled on your system.
  3. 3. Create the Macro: Click 'Macros', name a new macro (e.g., ResizeFrames), and click 'Create' to open the VBA Editor.
  4. 4. Execute the Code: Paste the wdFrameAuto macro code and press F5 to instantly resize all frames in your document.
Seamless compatibility with Microsoft Word formats (.docx, .doc)Built-in VBA editor to run existing macros without modificationAdvanced formatting tools to easily manage frames and paragraph stylesLightweight, fast, and completely free to download
microsoft office alternative - wps office

Frequently Asked Questions

Why does my VBA code fail when using 'Shape' to resize frames?

Microsoft Word treats Frames and Shapes as two entirely separate objects. Frames belong to the Frames collection and are closely tied to paragraph formatting, whereas text boxes are part of the Shapes collection. You must iterate through ActiveDocument.Frames instead.

What is the difference between wdFrameAuto and AUTO in Word VBA?

wdFrameAuto is the specific VBA enumeration constant (representing the value 0) required to tell a Word frame to automatically adjust its size. Typing 'AUTO' will return an 'undefined variable' error because it is not a recognized constant for frame sizing rules.

Can I set frame widths to exact but keep the height automatic?

Yes. In your VBA code, you can set f.WidthRule = wdFrameExact (while specifying a width via f.Width) and leave f.HeightRule = wdFrameAuto. This ensures the frame width remains fixed while expanding vertically to fit the pasted content.

How do I stop Word from pasting text into frames with exact dimensions?

If the source content relies heavily on exact framing, Word will attempt to retain that formatting by default. You can either paste the content using the 'Keep Text Only' option, or modify the default paragraph style in Word so that its embedded frame properties are preset to Auto.