0

enter image description herethe error is showed in image please check Here is the code for deleting the bookmark from word addin using js api

  Word.run(async (context) => {
            
            console.log("result", result);
            const range :any = context.document.getSelection();
            
            return context.sync().then(async function ()
            {
              context.load(range);
              await context.sync();
              let text = range.text
              console.log("item", item.ImageId, text);              
  
              if (item.ImageId == text) {
                console.log("item bookmark",item.bookmark)               
                range.hyperlink = "#" + item.bookmark;

                //delete the bookmark after 5 sec
                setTimeout(()=>{
                  console.log("setTimeout called")
                  range.deleteBookmark(item.bookmark)
                },5000)

              } else {
                console.log("range not matched");
              }
              
              await context.sync();
            });        
macropod
  • 12,757
  • 2
  • 9
  • 21

1 Answers1

1

try this:

await Word.run(async (context) => {
    const deleteBookmark = delete(context, '<bookmarkName>');
    console.log(deleteBookmark);
})


const delete=(context: Word.RequestContext, name: string)=>{
        const doc = context.document;
        context.sync();
        return doc.deleteBookmark(name);
    },
Sagar Mistry
  • 131
  • 11