Running an Access macro from Excel VBA

ferrell

New Member
Joined
Apr 19, 2007
Messages
36
I am attempting to run an Access 2003 macro from within Excel (2003) VBA.

I found this snippet of code from the mrexcel.com site...

http://www.mrexcel.com/archive/VBA/8278.html

Code:
Private Sub CommandButton1_Click()
Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "[Insert database path]"
appAccess.DoCmd.RunMacro "[Insert macro name]"
Set appAccess = Nothing
End Sub

I am simply testing this code in my own Excel file like this...

Code:
Sub Run_Access_Macro()

Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase "C:\test.mbd"
appAccess.DoCmd.RunMacro "Macro1"
Set appAccess = Nothing

End Sub

When I run this macro from Excel, I get the following error...

Code:
Run-time error '7866':

Microsoft Office Access can't open the database because it is missing,
or opened exclusively by another user.

Now, I have verified the Access database filename, and I am sure that the file is closed when I try to run this macro. The only thing that I can think of is the fact that the standard security warning appears when I try to open the Access file manually....Could this be part of my problem?

Thanks!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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