How do I use the setStartupBehavior API call? - excel

I am trying to register event handlers when a document first opens up in Excel as it shows in the documentation. However, it tells me that I need to configure my code to include this: Office.addin.setStartupBehavior(Office.StartupBehavior.load); I'm not too sure where I am supposed to use this. I created my project using the yeoman generator for Office.

It depends on whether you want the users to decide whether the add-in runs when the file opens or whether you want to ensure that it does. If you want the user to decide, include this line of code in an event handler for a button or other UI. There's a sample add-in that does this at: Excel shared runtime scenarios.
If you want to ensure that the add-in runs whenever the file opens, then include the line of code in the Office.initialize method or Office.onReady method. The first time the file opens, the add-in will not run immediately and the user will have to manually invoke it. But, after that, the add-in will run whenever that file is opened.

Related

Handle loading state of Excel AddIn or preload AddIn on insert

I'm developing an Excel AddIn and faced one issue.
1st issue: When user inserts the AddIn to the Excel (web) - user needs
to click any ribbon command to start loading plugin files.
2nd issue:
When plugin already inserted, the files are being downloaded.
However, if user click any command before files downloaded, nothing
happens.
I can disable all commands and enable them when source code downloaded. BUT this not works when user inserts AddIn for the first time. He MUST click any command to start downloading source code.
Question: is there any solution to force load Excel AddIn source on initial insertion?
P.S.
Startup behavior works only for the next opening of AddIn. If manifest has something similar - would be nice to know.
Env: Excel (on the web), OfficeJS API, Shared runtime, windows (if it's matter)
P.P.S. The problem - user clicks on enabled button to open taskpane, but nothing happens (the downloading just started).

Startup behavior doesn't work in Excel Desktop

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
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.

How to automatically show task pane for non-function add-in when opening worksheet?

How can we tell Excel (Web and Desktop) to load but not show an add-in automatically when a workbook is opened? We want code in the add-in to check the worksheet and, if our add-in has been used on it, open the add-in task pane automatically (though we'll give the user an opt-out of the behavior).
(The add-in is just a task pane, not custom functions.)
If you haven't already done that, I would recommed taking a look at the options for running code in your Office add-in when the document opens. From that page:
Configure your add-in to load when the document opens
The following code configures your add-in to load and start running when the document is opened.
Office.addin.setStartupBehavior(Office.StartupBehavior.load);
...
Place startup code in Office.initialize
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.

Launch one addin from another addin in excel

We have developed a couple of excel addins with office-js and are finding that it would be really handy to be able to launch one addin from another addin and even possibly pass some data between the 2. Is the launching at least possible?
If you own both add-ins, you could navigate to one or the other via the URL's you placed in your manifest file. This could allow you to launch another add-in, however it would be inside the same task pane.
You could also pass data between both apps via url query parameters.
I've done this before when I made an add-in that was a landing page for other add-ins. When you clicked on a button for another tool, it would navigate to another add-in (which was a separate project) and pass the previous tool as a parameter in the URL so you could navigate back to where you came from.
It'd also be possible to share data on a private sheet inside Excel.
This would be security issue when an add-in will be able to manipulate others. For this obvious reason this is not possible.
Usually I advise to use https://officespdev.uservoice.com/ to request unimplemented feature, but based on your description, Office team most likely won't allow it anyway.

Open an Excel file in running instance of Excel with Task Scheduler

I use Task Scheduler to automate a variety of nightly tasks using Excel. Typically the task opens a new instance of Excel, which in turn opens a specified file, which does some stuff and closes itself (and Excel).
Now I have a task that requires an add-in, and use of the add-in requires separate authentication. There is no way to pass my credentials - I have to manually authenticate when the add-in loads. Because the old-fashioned way always launches a new (unauthenticated) instance, I can't figure out how fully automate tasks that require the add-in.
One workaround would be to open an instance of Excel before I leave, authenticate for the add-in, and leave that instance open. Then I could theoretically schedule the opening of some file within that instance (as opposed to launching a new instance to open the file, as described above) and do whatever the tasks were that required the add-in.
Is it possible to do this, either directly by defining the task a certain way, or in a .bat file that I can run on a schedule?
I have a very similar problem and wondering if you have solved this problem through the VBA (getobject(), sendmessage method etc) yet.
I created a seperate question on this just show what I have done. Windows FindWindows and SendMessgae for Auto-authentication excel VBA
Basically I am stuck on how to pass user name and password to the add-in pop up window.
Thanks a million times:)

Resources