Run an Access Macro - VB Script

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
thughes
Newbie
Posts: 2
Joined: Tue Feb 10, 2009 2:04 pm

Run an Access Macro - VB Script

Post by thughes » Tue Feb 10, 2009 2:13 pm

Hi,

I'm new to this product and have been able to achieve much of what I want to by using the forums as well as the built-in help. Can someone help with running an Microsoft Access Macro. I use the following code to run an Excel Macro successfully (see below). I would like to know how to do the same for MS Access. Thanks in advance for your help!

//Put this VBScript block at top of script
VBSTART
Sub OpenAndRun(xlFileName, MacroName)
Set xlApp = CreateObject("Excel.Application")
'remove next line to make Excel invisible
xlApp.visible = true
Set xlBook = xlApp.WorkBooks.Open(xlFileName)
xlApp.Run(MacroName)
'Uncomment next line to quit Excel
'xlApp.quit
End Sub
VBEND

//Use this line when you want to run the Excel macro:
VBRun>OpenAndRun,c:\files\myexcel.xls,MyMacro
Tom Hughes
Swarovski Optik

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 10, 2009 2:56 pm

There is not a similar function in Access. But you can run an Access macro via the command line using the /x switch:

Run>c:\...\msaccess.exe /x macroname
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

thughes
Newbie
Posts: 2
Joined: Tue Feb 10, 2009 2:04 pm

Run an Access Macro - VB Script

Post by thughes » Tue Feb 10, 2009 3:09 pm

Thanks. So that I understand, do I just use this one command line:

Run>c:\...\msaccess.exe /x macroname

where the DB path is defined (including the DB name), and then specify the macro name within the DB for example:

Run>c:\Databases\mydb.accdb /x mymacro

Do I also use msaccess.exe portion of the statement?

Thanks again!
Tom Hughes
Swarovski Optik

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Feb 10, 2009 3:22 pm

Sorry, yes, I left a bit of info out. It would be:

Run>"c:\path\to\access\msaccess.exe" "c:\databases\mydb.accdb" /x myMacro


So you need Access, then the DB, then /x macroname
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Feb 10, 2009 4:44 pm

Also make sure that RP_WAIT is set properly for the macro to run in Excel and to allow the Macro Scheduler script to continue. See the HELP on RunProgram command.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts