Office Settings & Configuration

How to Set Table of Contents Direction to Right-to-Left Using Word VBA

Steven ParkerSteven Parker Oct 26, 2026 869 views

Question details

The user needs to change the reading order of a Table of Contents to Right-to-Left using a VBA macro.

How to Set Table of Contents Direction to Right-to-Left Using Word VBA
Product
Word
Device & OS
not provided
Scenario
Formatting a document in a right-to-left language (such as Arabic or Hebrew) where the Table of Contents requires RTL text direction.
Observed behavior
The text-direction option is disabled or unavailable in the standard Modify Style dialog for TOC 1 and TOC 2 styles, forcing the user to seek a VBA or Page Setup workaround.
Before you start

Ensure that the Developer tab is enabled in your ribbon to access the VBA editor, and verify that your document already contains a generated Table of Contents.

Solution 1Recommended

Use a VBA Macro to Modify TOC Style Reading Order

Execute a short VBA script to force the ReadingOrder property of TOC styles to Right-to-Left and update the entire table simultaneously.

Because Word restricts certain paragraph formats directly in generated TOC styles, using VBA bypasses the graphical interface limitations and applies the correct wdReadingOrderRtl property.

1
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.

2
Insert a New Module

In the Project Explorer pane on the left, right-click on your current document's project, select 'Insert', and choose 'Module'.

3
Paste the Macro Code

Copy and paste the following code into the module window: Sub Demo() Dim TOC As TableOfContents With ActiveDocument .Styles(wdStyleTOC1).ParagraphFormat.ReadingOrder = wdReadingOrderRtl .Styles(wdStyleTOC2).ParagraphFormat.ReadingOrder = wdReadingOrderRtl For Each TOC In .TablesOfContents TOC.Update Next End With End Sub

4
Run the Macro

Place your cursor inside the macro code block and press F5, or click the 'Run Sub/UserForm' button on the toolbar to apply the right-to-left direction.

Use a VBA Macro to Modify TOC Style Reading Order
Persistent Formatting: Once you run this macro, the ReadingOrder property is permanently changed for the TOC styles. The right-to-left format will persist even if you manually refresh the Table of Contents later.
WPS Writer Professional Tools

Use WPS Writer for Advanced Document Layouts and Macros

WPS Office provides seamless macro support and robust layout controls, allowing you to easily adjust text direction, manage Table of Contents styles, and execute VBA macros identically to Microsoft Word.

  1. 1. Enable the Developer Tab: Open WPS Writer, go to File > Options > Customize Ribbon, and check the 'Developer' box.
  2. 2. Open the VBA Editor: Navigate to the Developer tab and click 'Visual Basic Editor' (or press ALT + F11).
  3. 3. Insert the TOC Macro: Insert a new module and paste the provided Right-to-Left TOC macro code.
  4. 4. Execute and Save: Run the macro to update your Table of Contents, then save your document as a macro-enabled file.
Fully compatible with Microsoft Word (.docx) formats and stylingNative support for VBA macros for advanced document automationBuilt-in right-to-left text support for multilingual documentsLightweight, fast, and completely free to download
microsoft office alternative - wps office

Frequently Asked Questions

Why is the text direction option disabled in the Modify Style dialog for TOCs?

Word processors often lock certain structural styles like TOC 1 and TOC 2 to prevent manual formatting conflicts during automatic generation. Applying structural overrides requires a VBA script or modifying the section-level Page Setup.

Can I set the reading order for all TOC heading levels using this macro?

Yes. The provided macro targets TOC 1 and TOC 2. You can easily modify the script by adding additional lines (e.g., .Styles(wdStyleTOC3).ParagraphFormat.ReadingOrder = wdReadingOrderRtl) to cover deeper heading levels in your document.

Do I need to run this macro every time I update the Table of Contents?

No. The macro modifies the underlying style definitions (TOC 1 and TOC 2). Once the style is updated to right-to-left, subsequent automatic updates to the Table of Contents will inherit this new text direction.