Windows Task Scheduler starting Excel in background. How to force to start in foreground?

1

I'm using Windows Task Scheduler to restart MS excel when it crashes, via an event trigger that runs a vbs script (https://stackoverflow.com/questions/18504067/how-to-automate-the-forced-closure-of-excel-followed-by-a-restart/18654283#18654283).

Both excel and my long-running macro, successfully re-start when the trigger event occurs. However, the problem i'm having is that excel starts in the background.

When I remote log into the machine (as Administrator) the excel gui is nowhere to be seen. Under task manager one can see that excel.exe is running (as is my macro, since report files continue to be written).

If I run the vbs script manually (ie double click, when logged in) then excel starts in the foreground.

I've set the task scheduler to run the task as administrator, and to run whether the user is logged in or not. Are there any other settings I should be aware of that relate to starting excel in the foreground from a scheduled task?

I'm using Windows Server 2008R2 and excel 2010.

Thanks, Yug

Added: To be clear the difference in behaviour seems to be whether the script is run by task manager or is run manually (my being remote logged in or not is irrelevant. When task manager runs the script, it starts excel as hidden).

Yugmorf

Posted 2014-01-13T06:49:45.813

Reputation: 125

On the off-chance, what happens if you right-click excel in task manager and maximize the window?

Does this full-screen the application? – DLMono – 2014-01-29T05:30:07.830

The Excel application is NOT visible under the applications tab in taskmanager, so nothing to right click there. However excel.exe can be seen under the processes tab. Right clicking the excel.exe process gives a few options, none of which appear to help. – Yugmorf – 2014-01-29T10:23:20.333

Man, I have exactly the same problem.. I also tried to force it to maximize, but it didn't work.. Have you already found a solution? I also added a question,but on SO: http://stackoverflow.com/questions/21879435/how-to-start-a-program-with-command-line-arguments-on-windows-cmd-and-force-it

– periback2 – 2014-03-18T12:12:51.807

Answers

1

When Excel gets ran from the Task Scheduler, it's always hidden as a process because it's being ran from the service, whereas when you manually run it yourself, it isn't.

I previously had similar issues, and the way I resolved it was by creating a batch file instead. I let the task scheduler run the batch file, and then I let the batch file run Excel/scripts/macros. This allows Excel to open up the same way that you would if you manually opened it.

If you're not familiar with batch files, just google ".bat batch how to create" and there is an abundance of information out there on it for you.

In contrast, using your "problem" is a great way for you to automate reports and have them run in the background instead of displaying itself, which can be helpful in other situations.

Hope this helps!

Fata1Err0r

Posted 2014-01-13T06:49:45.813

Reputation: 126

0

In the Excel VBA, at the beginning of the long-running macro, insert this command:

Application.Visible=True

This makes Excel Workbook visible. It won't hurt if Excel is visible already.

Bob Monahon

Posted 2014-01-13T06:49:45.813

Reputation: 1

Tried that, didn't work. I suspect the answer might something to do with possible permissioning differences when starting excel from a user versus task manager. However, I don't know what the difference is or how it functions, or how to change it. – Yugmorf – 2014-04-14T16:02:27.517