How to Set Table of Contents Direction to Right-to-Left Using Word VBA
Question details
The user needs to change the reading order of a Table of Contents to Right-to-Left using a VBA macro.

- 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.
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.
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.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.
In the Project Explorer pane on the left, right-click on your current document's project, select 'Insert', and choose 'Module'.
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
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.

Isolate the Table of Contents and Modify Page Setup
If you cannot use macros, place the Table of Contents in a separate section and change the section's text direction via the Page Setup dialog.
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. Enable the Developer Tab: Open WPS Writer, go to File > Options > Customize Ribbon, and check the 'Developer' box.
- 2. Open the VBA Editor: Navigate to the Developer tab and click 'Visual Basic Editor' (or press ALT + F11).
- 3. Insert the TOC Macro: Insert a new module and paste the provided Right-to-Left TOC macro code.
- 4. Execute and Save: Run the macro to update your Table of Contents, then save your document as a macro-enabled file.

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.




