Search code examples
office-jsword-addins

How to manually create a Word.RangeCollection and add ranges to it?


In Word add-in API, Word.RangeCollection has the load() function while an array of Word.Range doesn't. Is there a way to manually create a collection and add ranges to it?


Solution

  • There is no way to "new" most objects in the Office JS library. You should loop through the array of Range objects and call the Range.load method on each one. (Note, the context.sync should be after the loop, not inside it.)