How to Run a Macro in Access from Excel VBA.

Hi Team,

Can you please tell me how to run a MS Access Macro from Excel VBA.

Note when I run the MS Access Macro it captures some data from some outlook public folders and updates the same as new records into our master table.  

And when we hit run for our access macro from excel VBA, the access file will not be open.
Sandesh555Asked:
Who is Participating?
 
Rory ArchibaldConnect With a Mentor Commented:
For example:
Sub RunAccessMacro()
   Dim objaccess As Object
   Set objaccess = CreateObject("Access.Application")
   objaccess.AutomationSecurity = msoAutomationSecurityLow
   objaccess.OpenCurrentDatabase "C:\test1.mdb"
   objaccess.DoCmd.RunMacro "macro_name"
End Sub

Open in new window

0
 
Sandesh555Author Commented:
Please note I am using MS Access 2007 and not Access 2003.  Will this code still work..
0
 
Rory ArchibaldCommented:
Yes, you just need to change the file name and path.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
TinTombStoneCommented:
You can't run an Access macro without opening the database

You could try something like

Sub RunAccessMacro()

Dim db As Object

Set db = CreateObject("Access.application")

db.opencurrentdatabase "Full path and database name"

db.docmd.runmacro "Name of macro"

End Sub

0
 
TinTombStoneCommented:
Sorry Rorya, I should have refreshed before I posted!
0
 
Rory ArchibaldCommented:
Would you care to explain how that differs from what I posted and why it is the accepted answer, please?
0
 
Sandesh555Author Commented:
Thanks Guys... my mistake also..
0
 
Sandesh555Author Commented:
Is their anything I can do.. :)
0
 
Rory ArchibaldCommented:
I've asked for it to be reopened for you. :)
0
 
Sandesh555Author Commented:
ok....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.