Task Scheduler to Run Macro?

Profector

Registered User.
Local time
Yesterday, 19:46
Joined
Mar 15, 2006
Messages
33
Hello All

Just got a new Windows 7 computer and installed Office 2013. I have a report that saves itself as a pdf in a temp folder and then attaches the pdf to an email and sends it out. I use a macro to run the report and everything works fine from there. I have a VBS file that runs the macro and clicking the vbs file makes everything work fine. the code is below.

When I tried to run it though the task scheduler it show as completing fine, but it doesn't. So I added a reference the vbs in a batch file (below) and output the logs to a temp file. After I ran the batch and opened the log I seen the message
Wed 03/19/2014 14:11:17.74 Username
C:\Users\*****\Desktop\Auto Reports\aragingrecent.vbs(1, 1) Microsoft VBScript runtime error: Permission denied: 'CreateObject'
Wed 03/19/2014 14:11:17.77

Any ideas? I turned UAC all the way down. turn off the virus scanner, and have local and domain admin access. I'm at bit a lose here. I had this working before but can't seem to remember how I did it. This is just one example I have several other reports that were schedule to run overnight, but they basically all use the same code and processes.




Code:
'launch macro
set accessApp = CreateObject("Access.Application")
accessApp.OpenCurrentDatabase "C:\Users\******\Desktop\Auto Reports\AgedTrialBalance.mdb"
accessApp.DoCmd.RunMacro "MCRecent"  
accessApp.CloseCurrentDatabase
accessApp.Quit
set accessApp = nothing

Code:
'My batch file
@echo off
 echo %date% %time% %username% >> c:\temp\test.txt
 cscript //nologo "C:\Users\*****\Desktop\Auto Reports\aragingrecent.vbs" 1>>c:\temp\test.txt 2>>&1
 echo %date% %time% >> c:\temp\test.txt
Exit
 
Last edited:
If it bitches about Create and you cannot resolve it ( I suspect it may have to do with which user is running the code from the task scheduler - it is not necessarily you ) then you could change tack. Access can take command line parameters - perhaps even a macro name, or jut a parameter that a macro can read, so you could just start up access normally but just supply the parameter with the command.
 
On the temp folder, where the pdf is saved, I changed the permissions to allow 'everyone' full access. After running the batch file started to the message
C:\Users\***\Desktop\Auto Reports\aragingrecent.vbs(1, 1) Microsoft VBScript runtime error: ActiveX component can't create object: 'Access.Application'

Then I created a new task and this time I changed "configure for" to "windows server 2003, Windows XP, Or Windows 2000". And it looks to me to be working fine now. I'm not using any of those directly, but the DB does have an ODBC to SQL server that's running on 2003R2. Let's see how it runs tonight.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom