Running Access Macro from Excel

B

Bob

I've got the following code that I would like to use to open an Access Macro
from excel however I am getting a compile error -"User defined type not
defined":

Sub AccessTest1()
Dim AccApp As Access.Application
Set AccApp = CreateObject("Access.Application")
Set AccApp.OpenCurrentDatabase ("C:\2008MRD.mdb")=
AccApp.DoCmd.RunMacro "Macro2"
AccApp.Quit
End Sub

Any suggestions as to what I should add/change?

Thanks.
 
B

Barb Reinhardt

I've not run Access macros from Excel, but I'd bet you need to add a
Reference to Access. In the VBA, try Tools -> References -> I'd guess it's
Microsoft Access ...

SInce I don't have Access loaded on this machine, I can't give any more
specifics.
 
M

Malik

Try this:

Sub AccessTest1()
Dim AccApp As Object
Set AccApp = CreateObject("Access.Application")
' Just to show you that it's working
AccApp.Visible = True
AccApp.OpenCurrentDatabase ("C:\2008MRD.mdb")
AccApp.DoCmd.RunMacro "Macro2"
AccApp.Quit
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top