Search code examples
ms-wordoffice-js

How can I find and edit/delete links from a Word document before JS requirement set 1.4?


I'm developing a MS Word Add-In using the JS API. Currently, I need to find and edit or delete specific links inside the entire document. I know that this works using context.document.body.fields and then item.result.delete() and item.result.insertText('new text', 'Replace'). But context.document.body.fields is only available in the latest versions of Word (technically since requirement set 1.4).

I just want to know, are there alternative ways to do this in older Word versions before rs 1.4? And if so, what are those?


Solution

  • I think you can use document.body.search() method to find the hyperlink and this method will return a Range object, you can futher call something like InsertText() to replace it or call range.hyperlink = "" to remove the hyperlink.