How to identify if spread sheet was started by the windows scheduler

andrewmi

New Member
Joined
Dec 5, 2013
Messages
2
Good day

I have Excel 2010 spread sheet that I need to automate and run using the Windows 7 task scheduler. The spread sheet works fine "interactively"; it opens, performs the tasks that it needs to and then closes down.

When I try to run the spread sheet via the Windos scheduler, it behaves differently i.e. a userform that should timeout after 5 seconds does not appear (it seems to be in background somewhere) and the spread sheet stays open waiting for keyboard input.

Is there a property that will tell me if the spread sheet was opened interactively or from the scheduler? I could then skip the userform if I know the spread sheet has been run from the sceduler.

Many thanks for taking the time to review.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I would recommend having the task scheduler call a VB script that opens the workbook. You can call a specific macro and have it tell your main program not to show the form.

sample vbs script
Code:
set xlApp = createobject("Excel.Application")
Set wb = xlApp.Workbooks.Open ("C:\tmpdata\Book1.xlsm", False, False)
xlApp.Run "ForcedUpdate"
wb.close false

so it opens Excel, opens the workbook. Then it runs the sub ForcedUpdate - which can then call your other sub, passing an argument to not open the userforms. I usually have the Save in the workbook (to control whether it should be saved or not), then close the workbook in the script, not saving changes.
 
Upvote 0
Thank you for the guidance; much appreciated.

I would recommend having the task scheduler call a VB script that opens the workbook. You can call a specific macro and have it tell your main program not to show the form.

sample vbs script
Code:
set xlApp = createobject("Excel.Application")
Set wb = xlApp.Workbooks.Open ("C:\tmpdata\Book1.xlsm", False, False)
xlApp.Run "ForcedUpdate"
wb.close false

so it opens Excel, opens the workbook. Then it runs the sub ForcedUpdate - which can then call your other sub, passing an argument to not open the userforms. I usually have the Save in the workbook (to control whether it should be saved or not), then close the workbook in the script, not saving changes.
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,841
Members
449,193
Latest member
MikeVol

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