2

I have an OfficeJS Excel Addin which is used in Online Excel and Desktop Excel. I use feature

Office.addin.setStartupBehavior(Office.StartupBehavior.load);

And it work fine for Online Excel: every time I start the excel - the plugin loads in background and ready to use.

However, in Excel Desktop it doesn't work. If I "alert" current behavior (after click on command to run the addin), it says "Load", but anyway it expects user interaction before to start loading the addin.

Any thoughts on this?

Prerequisites: SharedRuntime, Windows 10, Angular based addin

link to doc: https://learn.microsoft.com/en-us/office/dev/add-ins/develop/run-code-on-document-open

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
yamaxim
  • 171
  • 2
  • 6
  • I know from my testing, the only time an Add-In loads with a document in Desktop, is the Add-In must be ran once, w/ that line of code, then saved. Then, upon re-opening the document, the Add-In will load. But, I don't think there is a way to have Excel auto load an Add-In upon each start of every "new" document. Perhaps I'm wrong though – FreeSoftwareServers Feb 13 '23 at 19:09
  • @FreeSoftwareServers you are on the right avenue, the add-in will be loaded to the specific document, not all documents. – Eugene Astafiev Feb 13 '23 at 22:19
  • @FreeSoftwareServers it's ok for me, but even after add in loaded once with that line of code, anyway next time it doesn't load automatically. That's the main question of the topic – yamaxim Feb 14 '23 at 08:43
  • @EugeneAstafiev I work with only one document, and still have to manually load add in everytime I open that document – yamaxim Feb 14 '23 at 08:45

1 Answers1

0

You can configure your Office Add-in to load and run code as soon as the document is opened. This is useful if you need to register event handlers, pre-load data for the task pane, synchronize UI, or perform other tasks before the add-in is visible. When your add-in is configured to load on document open, it will run immediately. The Office.initialize event handler will be called. Place your startup code in the Office.initialize or Office.onReady event handler. Read more about that in the Run code in your Office Add-in when the document opens article.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • The wording of this makes it sound like `Office.onReady` runs for each new document that is opened, but from my testing, that is NOT the case (for Desktop). Can you confirm? – FreeSoftwareServers Feb 13 '23 at 23:14
  • Thank you, but this is from documentation. The problem is that the add in is not loaded into its sandbox, so no code to execute and no watchers available. Only after user clicks on any ribbon button of the plugin the index.html and js scripts starts downloading, and then office.onready is invoked. In web excel - when you open the document, plugin is initializing automatically – yamaxim Feb 14 '23 at 08:17
  • Make sure your Excel for desktop supports the shared runtime. See [Shared runtime requirement sets](https://learn.microsoft.com/en-us/javascript/api/requirement-sets/common/shared-runtime-requirement-sets?view=powerpoint-js-preview) fore more information. – Eugene Astafiev Feb 14 '23 at 08:59
  • 1
    @FreeSoftwareServers for a specific document. – Eugene Astafiev Feb 14 '23 at 09:00