MS Access RunCode Macro cannot find my procedure

前端 未结 9 1392
一整个雨季
一整个雨季 2020-12-10 11:24

I\'m only posting this since I wasn\'t able to find a solution anywhere. I finally figured it out. Kind of silly really.

When using the RunCode property within an

相关标签:
9条回答
  • 2020-12-10 11:44

    My VSTO C# calls to app.Run("MyMacro") stopped working suddenly and the error message started printing. ("Access cannot find the procedure MyMacro.")

    The problem on my machine was that my code (which connected to a running instance of Access) was connecting to a zombie database instance that did not have that VBA macro in it. Go figure. The zombie instance did not show in the Taskbar, in the Alt-TAB display, or in a list of windows that I printed out using a console program.

    The way I discovered it was to have my VSTO code print out the name of the database that it was connecting to. The Access database was one that I had been working with earlier in the day, without errors. I had closed the Access app holding it successfully hours before I tried running MyMacro.

    I can't think of anything that I did that was unusual, other than upgrading VStudio to the latest version. Probably a reboot will fix things. What a weird problem.

    0 讨论(0)
  • 2020-12-10 11:47

    Another solution that worked for me:

    The module name can NOT have the same name as the procedure(s) in the module(s).

    0 讨论(0)
  • 2020-12-10 11:49

    I had a similar issue with the error message. My VBA code had the following declaration:

    private function MyFunction()
    
    ....
    
    end function
    

    I removed private declaration to get the Macro Runcode to execute the MyFunction()

    For example:

    Function MyFunction()
    
    End Function
    
    0 讨论(0)
提交回复
热议问题