2
votes

This is the sequesnce of events I am trying to achieve: Scheduled Task- runs at the same time everyday and launches a VBScript VBScript Launches Excel Workbook and runs a Macro. Here is the snippet-

Set xlApp = CreateObject ("Excel.Application")
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open (xlFilePath,0,False)
xlApp.Run "Main"

Now the problem is if I run the task manually, It runs fine. When I run the scheduled task when I am not logged on to the server, it does not launch excel. What do I have to change in the code above to launch excel when no user is logged on? I have set Excel Macro security to Low.

Excel 2003 and Windows Server2003 64

3
do you know if Excel opens up fine? Meaning the VBScript runs, just not the VBA macro?Joseph
Excel doesn't open. I ran another VBScript to check if excel is running and I launched it at the same time as the scheduled task and it cannot find excel.exe in the processes.Kailas Deshpande

3 Answers

5
votes

Take a look at MS Knowledge Base - according to this, Office apps need an UI to run.

Thus, try using any user but the system user:

For example, code that is started by Task Scheduler under the SYSTEM account runs in the same environment as "server-side" ASP code or as DCOM code. Therefore, many of the issues that this article describes may occur.

Also, try to call Main from the Workbook_Open event in the Excel file instead of xlApp.Run "Main"...

3
votes

Not sure if it is already resolved, but I got the problem and resolved with the below steps.

Create the below folder(s)

(32Bit, always) C:\Windows\System32\config\systemprofile\Desktop

(64Bit) above folder and C:\Windows\SysWOW64\config\systemprofile\Desktop

This will resolve the issue if you are running with system account.

0
votes

You should be able to set an option to use a username when running the task as well as have the task run whether the user is logged on or not. Here's an example from Windows Server 2008:

enter image description here