Open MS Access Database and running it's maco from Excel

G

Guest

From Excel I want to open a MS Access Database and run a macro within it.

Can anyone please tell me the Excel VBA line code to do this?

Thanks KEN
 
M

merjet

Sub RunAccessMacro()
Dim appAcc as Access.Application

'Open Access or use it if already running
Set appAcc = New Access.Application
'Optional to show or hide Access
appAcc.Visible = True
'open desired database
appAcc.Open "C:\path\db1.mdb"
'to run Access macro
appAcc.DoCmd.RunMacro "MyAccessMacro"
'more optional code
'Close Access
appAcc.Quit
Set appAcc = Nothing

End Sub


You will need to set a reference in Excel to the Access
object library. Use menu Tools | References, and find
"MicrosoftAccess XX.0 Object Library," and check it.

Hth,
Merjet
 

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