| VBScript Excel Scheduled Task |
| Chris Wieman posted at Monday, November 03, 2008 11:08 AM |
I have a Scheduled Task (a CMD file with 2 lines of code (cscript script1.vbs and cscript script2.vbs) running on a W2000 server with MS Office 2003. Both scripts open Excel, execute a query, and format the returned data in a pivot table. If I run the script from the Command prompt, it runs successfully without error. The scheduled task opens Excel, but then does nothing. Excel can be seen in the Task Manager and exits only after the scheduled task timeout (Currently 2 hours).
I can include the script if you need it. |
 |
|
|
| |
Which user... |
| Charles Strahan replied to Chris Wieman at Monday, November 03, 2008 3:22 PM |
Are you using the same user to run the script in both cases? You might want to check file permissions and the such if you've selected a user to run the task under other than the the one you tested in the cmd prompt. That's pretty much all I can think of- that's pretty strange. Hope you get it figured out!
Regards, -Charles
|
 |
| |
| Other issues refered by Lalji Mer |
| Chris Wieman replied at Tuesday, November 04, 2008 10:07 AM |
The first reference does not apply, as I don't have a function in Excel trying to run. The script does all of the work. And I don't understand how the 2nd reference applies to me at all.
-chris |
 |
| |
| Other issues - Which User |
| Chris Wieman replied to Charles Strahan at Tuesday, November 04, 2008 10:08 AM |
In both cases (via schedule and locally) I'm running it as Network Admin.
Thanks,
-chris |
 |
| |
vbscript excel schedule task |
| C_A P replied to Chris Wieman at Tuesday, November 04, 2008 10:34 AM |
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")errJobCreated = objNewJob.Create _
("Excel.exe", "********040000.000000-420", _
True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated
This script will run excel every monday, wednesday and friday at 04:00,
then you can set at workbook_open to do what you want and close the
file.
I hope this helps!
source from : http://www.vbaexpress.com/forum/archive/index.php/t-2328.html also try this http://www.codeproject.com/KB/shell/ScheduledTaskWizard.aspx
|
 |
| |
Things that caused me issues - maybe some help |
| Peter Wylie replied to Chris Wieman at Monday, November 17, 2008 3:18 PM |
Hi Chris,
I had a similar problem to you and found a solution eventually. The best way to test for problems is to watch the task run while you're logged in as the same user. Using this method I was able to find out that 2 things in particular weren't helping
Macro Security - I've had to set this to 'low' (in Excel under Tools, Macros, Security) so that the 'Enable Macros/Disable Macros' prompt doesn't appear when Excel opens a macro workbook. This is far from ideal, so I'm now looking into digitally signing the macros.
AutoRecover - This has had to be completely shut down (in Excel under Tools, Options), as it was halting macro execution by forcing the 'user' to make a decision on what to do with potentially recovered workbooks from another session. There appear to be two settings for this - one referring to a specific workbook, and the other to do with the actual installation of Excel for that particular user - that's how I've interpreted it anyway. Both are in Tools, Options.
Unfortunately since last week the same problem has returned where Excel appears to open and then do nothing. I've stripped a test right back down to a macro which literally quits Excel as soon as it runs, and even that isn't currently working. I suspect a recent Windows update and believe the problem is either user permissions or something new in Excel - unfortunately that doesn't narrow it down very much.
Good luck,
Peter. |
 |
| |
| Other Issues - Excel via Scheduled task |
| Chris Wieman replied to Peter Wylie at Monday, November 17, 2008 3:26 PM |
Peter,
Thank you for the hints. But it works interactively, so Macro security and AutoRecover do not seem to be a part of the problem/solution. And worse, it functions perfectly under XP. So I have it running on my laptop, which is not ideal, as I have to leave it running.
Thank you,
-chris |
 |
| |
|
|