How to store word ranges in Word JS API for search on selection

Sebastian123 26 Reputation points
2023-01-03T14:08:37.42+00:00

I am trying to create a task pane add in that performs multiple wildcard searches, and lists the results in the task pane. The purpose is so that, when one clicks on one of the results, it highlights the particular word.
Currently, I am having trouble storing the ranges of each of the results. Is there a way of passing the collection of ranges from one function to another so that they can be selected using a second function.
For example, first, a function completes a search, loads the items and text, and populates a html table with text, item number, and button; and secondly, a function awaits a click of the button and gets the range of the result clicked? Currently, I am only able to do this by performing a second search & select function, but this presents problems when there are multiple results and changes are made to the document.
Any assistance would be greatly appreciated.

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
842 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,896 questions
0 comments No comments
{count} votes

Accepted answer
  1. John Korchok 5,326 Reputation points
    2023-01-03T17:40:21.053+00:00

    There aren't any Office.js experts here. Please try posting your question in Stack Overflow with the office.js tag: https://stackoverflow.com/questions/tagged/office-js

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sebastian123 26 Reputation points
    2023-01-04T01:20:22.533+00:00

    Thank you very much, I found my answer there. For those interested, see the following answers on using a range across different Word.run contexts:
    https://stackoverflow.com/questions/37275482/how-can-a-range-be-used-across-different-word-run-contexts

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.