Run Access Macro from Excel

bradyboyy88

Well-known Member
Joined
Feb 25, 2015
Messages
562
Hi,

I have seen numerous posts of this done but I keep running into the error Method 'Run' of object '_Application' failed. The code in access just has the following:

Code:
Public Sub TestMacro()
msgbox "test"
End Sub

Then in excel I use the following:

Code:
Public Sub TrackerAutomation()
    
    If Not FileInUse(DatabaseDirectory) Then
        Dim AccDB As Access.Application
        Set AccDB = CreateObject("Access.Application")
        
        On Error GoTo ErrorHandler
        
        AccDB.OpenCurrentDatabase DatabaseDirectory, True


        AccDB.Visible = False


         AccDB.Run "testMacro"


        AccDB.Quit
    Else
       
    End If
    
ErrorHandler:


    Debug.Print Err.Description
    AccDB.Quit
End Sub

I have the reference for Access 15.0 library as well. One thing that is strange when we were testing this run command it seemed to work on a 64bit laptop which had windows 10 . THat laptop was actually used to make the access DB and macro. It originally had object library 16.0 referenced but since windows 8.1 doesnt have that I disabled that and made 15.0.

Thanks
Shaun
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
In order to rule out whether it is a library reference issue, try late binding the access app.

Just change your one line of code:
Code:
[COLOR=#333333] [/COLOR][COLOR=#333333]Dim AccDB As Access.Application[/COLOR]

to

Code:
[COLOR=#333333]Dim AccDB As object[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top