Determine whether scheduled tasks opened a workbook

Steve_R

Active Member
Joined
Oct 28, 2015
Messages
350
I need a WB to auto_close after Scheduled Tasks opens it but stay open when a user opens it manually. Is there a way to determine via VBA when a WB was opened by tasks (or, looking at the problem from another angle, not opened by a user)?
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Another alternative is to use an intermediary workbook when opening the target workbook manually.

Upon opening,this intermediary workbook will set an application flag , open the target workbook and close itself silently .

When the workbook is then opened, it will read the flag to determine if it was opened manually or via Task Scheduler.

If you like the idea I can show you the code.
 
Upvote 0
Time() might also work but occasionally insomnia takes hold...

All it needs at this stage is to hold it together until the decision is made whether or not anything of value is coming out of the data. So far, that's about six year. Up until very recently, Wscript was working well (which is the reason I started out removing updates and did a repair install; the System Restore attempt was after the backups so, too late).

The project started small but is organic, complex and expanding (albeit now slowly). If the ultimate decision is to continue, there'll be one back end for each of the components that scrape, reformat, extract, parse, re-order, etc data and a single front end.
 
Upvote 0
Working on Win 10:

Using code and instructions at Post #6 I tried many methods to set up Task Scheduler to run with the argument "TaskScheduler" but nothing I tried worked. The task kept running with no visual feedback of the Command Line so I went back to creating a shortcut to test the format. The only way I could Get 'TaskScheduler' to appear in the CommandLine was to rename the WB including 'TaskScheduler' in the name.


Workbook Name - TaskSchedulerTest.xlsm
Shortcut target - "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" D:\TaskSchedulerTest.xls
Using those names the code made the right decisions as follows:


CommandLine when opening the workbook direct:-
"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" /dde
The workbook did not close

CommandLine when opening via shortcut:-
"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" D:\TaskSchedulerTest.xlsm
The workbook did close

It should be a doddle to do that within Task Scheduler and remove the shortcut - another day.

Without testing, I suspect finding the result of ActiveWookbook.Name within CommandLine should work.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top