In Microsoft Word, we can use the following VBA command to select the current page where the cursor is placed: ActiveDocument.Bookmarks(“\Page”).Select
This is useful for getting the entire page’s content programmatically. I’m trying to achieve something similar in ONLYOFFICE — either by selecting:
The current page based on cursor location, or
A specific bookmark’s content
Is there a way to do this in ONLYOFFICE using macros, API, or plugins?
Any example or documentation reference would be greatly appreciated.
Thanks @carl
I have a 6-page document, with each page having a bookmark. I need to select bookmarks for specific pages — for example, I want to select the bookmarks on pages 2 and 3.
(function () {
const document = Api.GetDocument();
// Define the pages you want to select bookmarks for
const pagesToSelect = [2, 3];
pagesToSelect.forEach(pageNumber => {
const bookmarkName = `page_${pageNumber}`;
const range = document.GetBookmarkRange(bookmarkName);
if (range) {
range.Select();
console.log(`Selected bookmark: ${bookmarkName}`);
} else {
console.warn(`Bookmark not found: ${bookmarkName}`);
}
});
})();