How to Convert Word Index Page Numbers into Ranges Without VBA
Question details
The user wants to format consecutive page numbers in a document index as a continuous range (e.g., 12-16) instead of listing individual numbers, without using VBA macros.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Creating and formatting a professional document index where a single topic spans across multiple consecutive pages.
- Observed behavior
- Index entries currently display each page number individually separated by commas, and the goal is to condense consecutive numbers into a single hyphenated range.
Ensure that hidden formatting marks are visible in your document so you can view and edit the hidden XE (Index Entry) fields. You can toggle this by clicking the Show/Hide Paragraph button on the Home tab.
Use an XE Field with the \r Switch and a Bookmark
This is the most reliable native method to create index page ranges. By bookmarking a section of text and referencing that bookmark within your index entry, the software automatically calculates and formats the page range.
Instead of relying on complex VBA macros, you can use the built-in XE (Index Entry) field codes combined with bookmarks. The \r switch instructs the index to span the entire page range covered by the specified bookmark.
Highlight the entire section of text that spans the multiple pages you want to index. Navigate to the 'Insert' tab, click 'Bookmark', type a recognizable name without spaces (e.g., 'TopicRange1'), and click 'Add'.
Place your cursor at the beginning of the bookmarked text. Press Ctrl+F9 to insert empty field code brackets { }. Inside the brackets, type the index entry code formatting: XE "Your Index Term" \r "TopicRange1".
Scroll down to your document's Index. Right-click anywhere inside the index and select 'Update Field', or simply click it and press F9. The consecutive page numbers will now automatically format as a range (e.g., 12-16).

Easily Manage Document Indexes and Bookmarks with WPS Office
WPS Writer provides comprehensive support for advanced document formatting, including complete compatibility with field codes, XE index entries, and bookmark references. You can easily set up page ranges for your index entries to create clean, professional-looking documents without writing code.
- 1. Create a Bookmark: Open your document in WPS Writer, highlight the text spanning your desired pages, go to the Insert tab, click Bookmark, and save it with a unique name.
- 2. Insert the Field Code: Press Ctrl+F9 to insert field brackets, and type the XE formula using the \r switch and your bookmark name (e.g., { XE "Topic" \r "MyBookmark" }).
- 3. Generate or Update Index: Go to the Reference tab, click Insert Index to create your index, or simply press F9 on an existing index to refresh and display the formatted page ranges.

Frequently Asked Questions
Why are my XE fields visible in the document text?
XE fields are formatted as hidden text by default. If you can see them, you currently have hidden formatting marks toggled on. You can hide them by going to the Home tab and clicking the 'Show/Hide ¶' button, or by pressing Ctrl+Shift+8.
Why didn't my index update immediately after adding the field code?
Document indexes do not update in real-time as you add new entries. You must manually prompt the index to refresh by right-clicking it and choosing 'Update Field', or by clicking inside the index and pressing the F9 key.
Can I use multiple bookmarks for a single index entry?
A single XE field code with the \r switch can only reference one bookmark at a time. If a topic appears in multiple separate page ranges throughout the document, you will need to create separate bookmarks and separate XE fields for each instance.




