-
Excel VBA to add/delete windows scheduled task
Hi all,
I'm using windows XP and Ms office 2003, I do need an urgent help to
add a scheduled task using Excel VBA to run .xls file for one month.
Then I need a code in Excel VBA to delete the same scheduled task after one month.
Please help.
Thanks in advance.
-
Check out OnTime in VBA Help, or is there more going on?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
There are two methods to use schtasks. One is by its API and the other is by the schtasks.exe. For the latter, put it and the command line parameters string in a Shell() command. For the former, that can be rather involved.
If you use the latter, try putting the string for the Shell() command into Start > Run, to make sure that the string is correct. The usual problem is that a string with space characters was not enclosed with quotes. You can also test using that string in a BAT file. Once you have the string built properly, you can build the string in VBA for Shell().
The best source for both methods is: http://msdn.microsoft.com/en-us/library/aa383608
There are various other API examples.
1. http://www.tek-tips.com/viewthread.cfm?qid=356060
2. http://www.andreavb.com/forum/viewtopic_1507.html
-
Thanks for your help, but still couldn't get it.
Please see below code and tell me what's wrong with it as WHS:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")errJobCreated = objNewJob.Create _
("C:\222\test.xls", "********073000.000000-420", _
True , 1 Or 2 Or 4 Or 8 Or 16, 32 ,64 , JobID)
Wscript.Echo errJobCreated
Brothers, again I'm very thankful for your help.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules