Skip to content

createDocument() Works on Desktop but Not in Word Online #5507

Closed
@dmytro-kachurynets

Description

@dmytro-kachurynets

Host: Word
Office version number: Latest
Operating System: macOS
Browser: Google Chrome

I’m developing a Word add-in using Office.js and encountered an issue with the createDocument() method. My code works as expected in the desktop version of Word, where it successfully creates and opens a new document. However, in Word Online, instead of opening a new document, I only see the popup message:

"This add-in is about to create a new document in your default folder on your current cloud repository."

After that, no new document appears, and nothing seems to happen. Here is the relevant code snippet:

export const createNewDocument = async (): Promise<void> => {
  try {
    await Word.run(async (context) => {
      const newDoc: Word.DocumentCreated = context.application.createDocument();
      newDoc.open();
    });
  } catch (error) {
    console.error("Error creating document:", error);
  }
};

My questions are:

  1. Is context.application.createDocument() officially supported in Word Online?
  2. If it is supported, is there a workaround to ensure that the newly created document actually opens?
  3. If it’s not supported, is there an alternative method for creating and opening a new document in Word Online?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions