?
Solved

How to Run a Macro in Access from Excel VBA.

Posted on 2011-05-09
11
Medium Priority
?
465 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:Sandesh555
  • 4
  • 4
  • 2
10 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 35719149
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
 

Author Comment

by:Sandesh555
ID: 35719160
Please note I am using MS Access 2007 and not Access 2003.  Will this code still work..
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35719205
Yes, you just need to change the file name and path.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 6

Expert Comment

by:TinTombStone
ID: 35719236
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
 
LVL 6

Expert Comment

by:TinTombStone
ID: 35719254
Sorry Rorya, I should have refreshed before I posted!
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35719257
Would you care to explain how that differs from what I posted and why it is the accepted answer, please?
0
 

Author Comment

by:Sandesh555
ID: 35719330
Thanks Guys... my mistake also..
0
 

Author Comment

by:Sandesh555
ID: 35719334
Is their anything I can do.. :)
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35719356
I've asked for it to be reopened for you. :)
0
 

Author Comment

by:Sandesh555
ID: 35719384
ok....
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question