I'm creating an add-in in Excel where I want to detect changes in the workbook when the taskpane is not open and run custom code when the document is reopened / reloaded.
I have a button in my add-in where the user can set start up behaviour to load which triggers this code:
Office.addin.setStartupBehavior(Office.StartupBehavior.load);
I have tried using both Office.onReady() andOffice.initialize but neither one is invoked when the document is reloaded after the setStartupBehavior has been set to load.
I have followed the Microsoft documentation on these matters but still have a problem in Excel online.
Documentation that I have been following:
Configure your Excel add-in to use a shared JavaScript runtime
Run code in your Excel add-in when the document opens
Please note that this function works in the Excel desktop app but not in Excel online. Also, this add-in is still in dev mode and has not been published live.
That Office.onReady() / Office.initialize should run afther the Office.addin.setStartupBehavior(Office.StartupBehavior.load); parameters have been set when reloading / reopening the document. It should print out into the console "Hello world!".
After setting the Office.addin.setStartupBehavior(Office.StartupBehavior.load); parameters the onReady() / initialize is never called on document open unless the taskpane of the add-in is opened which is not the expected behaviour.
Add to manifest.xml (As described in the "Configure your Excel add-in to use a shared JavaScript runtime" documentation)
<Runtimes>
<Runtime resid="Taskpane.Url" lifetime="long" />
</Runtimes>
Add to package.json under dev dependencies
"@types/office-js-preview": "^1.0.85",
npm i
add to index.tsx Office.initialize()
Office.addin.setStartupBehavior(Office.StartupBehavior.load);
console.log("Hello world!");
npm run dev-server
Sideload AddIn into browser: Insert -> Add-ins -> Manage My Add-ins-> Upload Manifest.xml
Open sidePane to trigger Office.initialize which sets startupBeheaviour to load
Reload document
We are trying to create an Excel add-in which can be used both online and on the desktop client. It detects changes in the Excel worksheet even when the add-in is not open or loaded. For starters this add-in will only be using the taskpane and run code on reload / refresh.
Thanks for reporting this @ivark16.
@jeremy-msft or @shaofengzhu, could you please help with this shared runtime issue?
Thanks for your report @ivark16, we'll take a look and get back to you soon.
@jeremy-msft Any update here? Thx.
We are able to reproduce the issue and currently investigating a fix.
We are experiencing the same issue. Calling Office.addin.setStartupBehavior(Office.StartupBehavior.load) outputs the following error to console: RichApi.Error: This operation is not implemented.

Hi, are there any updates on this issue?
Hi @ivark16, thanks for your patience. This should now be fixed; please let us know if you continue to see the problem.
It seems to be working now, thank you guys so much! 馃槂
You're welcome, we're glad we were able to resolve this!
Hi @jeremy-msft,
I have run into this issues again. After deploying my add-in code to Azure App Service I noticed this problem has resurfaced. I have tried with the same code running both locally (running the code on localhost) and live from Azure App Service. It all works when run locally but the bug is still present when hosting the add-in on azure.
Hi @ivark16, we were not able to repro your issue using a sideloaded manifest pointed to a non-localhost server. Can you please provide additional details about your environment and any console errors you are seeing? Is the server URL the only difference between your two manifests? Does it work fine on the Desktop client? Also, please let us know the build number shown in Online under File -> About.
Hi @jeremy-msft,
Thanks so much for your answer. I decided to take a closer look at this problem. The manifest file that is producing the bug is distributed by centralized deployment through the admin center (via this documentation). I decided to take my existing manifest file that references my live Azure code and insert it manually as an Add-in in Excel online instead (the same file that is distributed by centralized deployment).

By doing that I was not able to reproduce the bug, everything worked as it should. So that got me thinking if the bug is linked to distributing the add-in via centralized deployment? That is the only difference I can think of.
Regarding your other questions:
@ivark16, thanks for the details. We are still in the process of addressing this issue for Centralized Deployment; we'll update you once that fix is rolled out. Re-opening this issue for tracking.
This should now be resolved. Please let us know if you continue to see issues.