Run Access Macro from Excel
Results 1 to 2 of 2

Thread: Run Access Macro from Excel
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Feb 2015
    Posts
    503
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Run Access Macro from Excel

    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

  2. #2
    Board Regular
    Join Date
    Dec 2009
    Posts
    273
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Run Access Macro from Excel

    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:
    Dim AccDB As Access.Application
    to

    Code:
    Dim AccDB As object
    My favorite Excel Add-in:= Nutilities

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •