Web Word not allow undo when the OOXML is set via my Addin

Günther Grill | headwAI GmbH 20 Reputation points
2026-01-08T12:43:50.4533333+00:00

Hi,

I have a simple Addin:



Office.onReady((info) => {
  if (info.host === Office.HostType.Word) {
    document.getElementById("set-content").onclick = setContent;
  }
});

export async function setContent() {
  const contentType = document.querySelector('input[name="contentType"]:checked').value;
  const content = document.getElementById("content-input").value;
  if (!content.trim()) {
    console.log("Content is empty");
    return;
  }
  await Word.run(async (context) => {
    // Replace body
    switch (contentType) {
      case "plain":
        context.document.body.insertText(content, Word.InsertLocation.replace);
        break;
      case "html":
        context.document.body.insertHtml(content, Word.InsertLocation.replace);
        break;
      case "ooxml":
        context.document.body.insertOoxml(content, Word.InsertLocation.replace);
        break;
    }
    await context.sync();
    console.log(`${contentType.toUpperCase()} content has been set`);
  });
}


When I run this in the online version of Word, for text and html, it is easily possible to undo/redo after text got inserted. No problem. But when I use OOXML as type, the following dialog appears:

User's image

(this doesn't appear for the other types), and when that dialog is gone, the OOXML is inserted but I cannot do any undo any more.

I also doubt that the OOXML itself is the issue, because what I do is:

  • Getting the corrent OOXML
  • Modify one word of the text
  • Put the full changed OOXML back

If I do the same thing with OOXML in the desktop version, this works as expected. I can undo even if OOXML is used.

Any ideas?

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Gabriel-N 12,110 Reputation points Microsoft External Staff Moderator
    2026-01-08T15:37:05.09+00:00

    Hi Günther Grill | headwAI GmbH

    Thank you for reaching out via the Microsoft Q&A forum and sharing your add-in scenario and the issue you encountered with undo behavior in Word Online when using insertOoxml.

    I’ve been looking into the undo issue you mentioned when using insertOoxml in Word Online, and I think the behavior might be tied to how Word Online handles document updates compared to Word Desktop.

    From what I’ve seen, Word Online doesn’t fully reflect the rich editing behaviors of the desktop app. Some features available on Desktop, like certain field types or content controls, don’t behave the same way or are missing entirely in the web version. So it’s possible that this difference in platform capabilities is also why the undo stack behaves differently when inserting OOXML.

    Also, when I read through Microsoft’s official documentation, I noticed they list OOXML insertion last among the recommended methods for Word add-ins, with the note:

    User's image

    So maybe the takeaway here is: for small edits, it’s better to stick with the standard Word JS APIs (like insertText, insertHtml) which preserve undo behavior across platforms. And only use insertOoxml when you really need to insert something complex, but with the understanding that undo won’t be available in Word Online.

    Some users seem to work around this by enabling Track Changes before inserting OOXML, so they can reject the change later. Others rely on version history in OneDrive or SharePoint to restore the document if needed. These aren’t perfect solutions, but they might help in cases where undo is important.

    Hope this info is helpful.


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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