Executing a VB script to run a Macro

tylersontag

Registered User.
Local time
Today, 01:36
Joined
Sep 2, 2009
Messages
19
Hey all,

I've made a macro that automates a load process and i'm trying to figure out a way to automate the running of this macro :-)

I've been working with a VBS file, but not with much luck. Its pretty barebone:

Code:
strFile = "C:\MDB_file_Path\MDB_File.mdb"
Set objAccess = GetObject(strFile, "Access.Application")
objAccess.DoCmd.RunMacro "AutoLoad"
objAccess.Quit
Set objAccess = Nothing

Any ideas? i'm executing the file with the windows command cscript... should i use a different compiler? I notice i'm using alot of implicit declarations, do i need to be more explicit? I'm sure its something simple but i'm having trouble tracking down a soultion via google.

Thanks!
 
Here is the code I use that has been working good for me. I execute it with the job scheduler that comes with windows.


Code:
'Read from a Microsoft ACCESS database

Option Explicit

dim oaccess

'execute another Access macro
set oaccess = createobject("access.application")
oaccess.opencurrentdatabase "C:\MDB_file_Path\MDB_File.mdb"
oaccess.docmd.runmacro "AutoLoad"
oaccess.closecurrentdatabase
oaccess.quit
set oaccess=nothing


WScript.Quit(0)

Hope this helps.
Gregg
 
Have you consider using the Windows Scheduler?

You can do this kind of thing with the Scheduler.
 
Any ideas? i'm executing the file with the windows command cscript... should i use a different compiler? I notice i'm using alot of implicit declarations, do i need to be more explicit? I'm sure its something simple but i'm having trouble tracking down a soultion via google.

Thanks!

Instead of CSCRIPT, use WSCRIPT.
 
Works like a charm (with wscript and cscript) changing the object to Create rather than Get. Thanks all!
 

Users who are viewing this thread

Back
Top Bottom