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

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:)

Related

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 do I use the setStartupBehavior API call?

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.

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.

Disable VBA script creation or modification in MS Office apps

as the title suggests. Allow execution of previously created scripts but disallow creation of new ones or modification of existing script. Blocking of VB doesn't work since the editor spawns as the parent process.
You can always protect the existing VBA project:
From the VBA Editor, select Tools > VBA project properties > Security > Lock project for viewing, enter a password and save.
Additionally, Modern versions of MS Access provide a method to save your database as a compiled executable format (*.accde) which you can then publish to your users without fear of them modifying or inserting VBA code.

How to prevent Windows Explorer from reusing the existing Excel instances?

I have a number of different programs where I create Excel instances and control them via OLE automation. In some cases the user can also work with these instances through Excel UI (which may involve opening other workbooks), in others they remain hidden.
Problems arise when the user double-clicks an Excel file in Windows Explorer to work with it for some other, unrelated purpose. Explorer would grab any running instance and open the file in it, which may interfere with a running macro, or the instance may be currently hidden and thus unusable via UI.
Is there a way to create an Excel instance in a "special" way to prevent it from being seen by Explorer?

Resources