How to Get Word Bookmark Range Start and End Positions with Office.js
Question details
The user needs to retrieve the start, end, and reference page positions of a bookmark range using the Word JavaScript API.

- Product
- Microsoft Word (Office.js)
- Device & OS
- not provided
- Scenario
- Developing a Word add-in using the Office.js API and manipulating bookmarks within a document.
- Observed behavior
- The user is calling getBookmarkRangeOrNullObject but needs the exact properties or methods to extract the start and end positions, including the page reference.
Ensure you are familiar with the asynchronous nature of the Word JavaScript API and have your add-in development environment open.
Seek Developer Support on Stack Overflow
Since Office.js is a specialized Microsoft development framework, Stack Overflow is the officially recommended platform for API-specific troubleshooting.
The Word JavaScript API handles document positioning differently than older COM/VBA models. Extracting absolute page numbers or index-based start/end positions often requires specific workarounds, as Office.js abstracts the document into flow content.
Gather the specific JavaScript or TypeScript code where you are calling context.document.getBookmarkRangeOrNullObject('BookmarkName').
Note down your Word API requirement set version (e.g., WordApi 1.3) and the host platform (Word on the Web, Windows, or Mac) where the issue occurs.
Submit your detailed question to Stack Overflow. Ensure you apply the 'office-js' and 'ms-word' tags so that developers familiar with the Word API can locate and answer your query.

Load Required Range Properties in Office.js
Understand the standard procedure for interacting with ranges retrieved via getBookmarkRangeOrNullObject.
Try WPS Office for Your Document Needs
If you are encountering limitations with Microsoft Office or its add-in ecosystem, consider switching to WPS Office. It provides a lightweight, highly compatible alternative for viewing, editing, and managing Word documents seamlessly.
- 1. Download WPS Office: Visit the official WPS website and download the free installer for your operating system.
- 2. Install and Launch: Run the installer, follow the simple on-screen instructions, and launch WPS Writer.
- 3. Open Your Word Documents: Drag and drop your existing .docx files into WPS Writer to continue editing with full formatting compatibility.

Frequently Asked Questions
Can I get the exact page number of a bookmark in Office.js?
Office.js does not provide a direct property for absolute page numbers on ranges because Word documents dynamically paginate based on the viewing environment. You may need to explore API workarounds or rely on text-based markers instead of absolute pagination.
What does getBookmarkRangeOrNullObject do?
It is a method in the Word JavaScript API that returns a Range object representing a specific bookmark. If the bookmark does not exist in the document, it returns a null object, preventing your add-in from crashing due to an undefined reference.
Where is the best place to ask Office.js API questions?
Microsoft recommends using Stack Overflow with the 'office-js' tag. This ensures your question reaches the developer community and Microsoft engineers who specialize in Office extensibility.




