Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call an Access Macro from Within Excel 1

Status
Not open for further replies.

DanAuber

IS-IT--Management
Apr 28, 2000
255
FR
Can anyone tell me the code to run an Access Macro from within Excel (via an Excel Macro)

let's say that:
The Access Database is C:\Accessdb.mdb and the macro is runmac

Thanks for the help

Dan

 
Try this:

Shell("msaccess c:\accessdb.mdb /xRunMac")

This worked for me based on a test I did on my computer. You may need to add the full path for msaccess. Also, This will open an instance of Access in order to run the macro, so you'll probably want to add a Quit command to the macro to give control back to Excel.
 
I use this:
Code:
Dim objAcc As Access.Application
Set objAcc = New Access.Application
With objAcc
    .OpenCurrentDatabase "C:\Accessdb.mdb"
    .DoCmd.RunMacro ("runmac")
    .CloseCurrentDatabase
    .Quit
End With
Set objAcc = Nothing

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
By the way: for future reference, please post VBA/Macro-specific questions in forum707, the VBA Visual Basic for Applications (Microsoft) Forum.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Sorry anotherhiggins, your code returns the following error:

"Compile error

User-defined type not defined"

can I get round this ?

 
Sure. In the VB Editor, go to Tools > References and check the box beside Microsoft Access X.X Object Library (the X.X represents whatever version number you have).

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top