How to Right-Align a Nested Word Table with VBA
Question details
The user needs to align a nested table to the right using a VBA macro, as standard paragraph alignment commands do not affect the table itself.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- Writing or troubleshooting a VBA macro designed to format layout and alignment of tables that are nested within other table cells.
- Observed behavior
- Applying paragraph alignment only formats the text inside the cell, failing to right-align the actual nested table structure.
Ensure you have the Developer tab enabled to access the VBA Editor, and make sure to save a backup of your document before running new macro scripts.
Use Direct Table Reference for Row Alignment
Directly referencing the nested table and modifying its row alignment property is the most reliable and efficient method.
Standard paragraph alignment commands only impact text. To align an entire nested table, you must modify its specific row alignment property.
Using direct object referencing instead of the Selection object is a best practice. It prevents the application from refreshing the screen after every command, which significantly improves macro execution speed.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor and locate your active module.
Determine the exact index of the parent table and cell. For example, to target the cell in row 2, column 3 of the first table, use: ActiveDocument.Tables(1).Cell(2, 3).
Append the nested table reference to your target cell. Since it is the first table inside that cell, use: .Tables(1).
Apply the right-alignment property to the rows by adding .Rows.Alignment = wdAlignRowRight to the end of your reference. The final code should look like: ActiveDocument.Tables(1).Cell(2, 3).Tables(1).Rows.Alignment = wdAlignRowRight.

Use the Selection Object for Active Cursors
If your macro is designed to execute based on wherever the user's cursor is currently positioned, you can use the Selection object.
Try WPS Office for Seamless Document Formatting
If you are tired of wrestling with complex Word macros and formatting quirks, WPS Office provides a lightweight, free, and highly compatible alternative. It handles complex layouts, nested tables, and advanced document editing with an intuitive interface.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Install WPS Office: Run the installer and follow the on-screen prompts to set up WPS Office on your computer.
- 3. Open Your Documents: Launch WPS Writer and open your existing .docx files to seamlessly edit tables and layouts.

Frequently Asked Questions
Why doesn't standard paragraph alignment work on nested tables in Word?
Paragraph alignment commands only format the text content residing inside the table cells. To move the structural boundary of the table itself, you must interact with the table's row alignment properties.
How do I center a table using VBA?
You can center a table by modifying the row alignment property to wdAlignRowCenter. For example: ActiveDocument.Tables(1).Rows.Alignment = wdAlignRowCenter.
Why is it recommended to avoid the Selection object in VBA?
Using the Selection object causes the word processor to refresh the user interface on the screen after every single action. This drastically slows down macro execution and can cause screen flickering. Direct object referencing (like ActiveDocument) bypasses this and processes code in the background.




