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

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top