0

I am developing an add-in for word. I am trying to replace a bookmark with a text. (My initial target was to insert text in the bookmark but there is a bug in the API so this is the alternate approach. Earlier question link)

Here is my code:

Word.run(function (context) {

    var doc = context.document;

    //get the bookmark range object by its name
    var bookmarkRange=doc.getBookmarkRangeOrNullObject("cscasenumber01");

    //insert a data and replace thee bookmark range
    bookmarkRange.insertText("test data",Word.InsertLocation.replace);

    // Synchronize the document state by executing the queued commands, 
    return context.sync();

}).catch(errorHandler);

But it throws exception. The error trace message is:

"GeneralException: GeneralException at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:211625) at ai (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248841) at ft (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248928) at d (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:248748) at c (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.js:21:247444)"

So is there any solution for it or it is another bug in the API ?

Note: I am using 1.4 beta version of the office.js API.

1
  • Can you using the released version of the api? Commented Oct 2, 2017 at 3:41

1 Answer 1

1

You need to test for whether bookmarkRange is a null object. Please try this code:

var bookmarkRange=doc.getBookmarkRangeOrNullObject("cscasenumber01");
bookmarkRange.load();

return context.sync()
.then(function() {
   if (bookmarkRange.isNullObject) {
        // handle case of null object here
   } else {
        bookmarkRange.insertText("test data",Word.InsertLocation.replace);
   }
})
.then(context.sync)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes. It does not give null object.I have tested your code but no luck.Still it is giving the same exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.