Run a macro in Access from excel

Vigneshrs87

New Member
Joined
Apr 19, 2011
Messages
12
Hi,

I have some code in Module 1 of the vba editor of access as follows.

sub Hi ()
code here....
end sub

I need to call this from excel how am i supposed to do that.

Thanks for your help.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Dim objAcc As Object
 
Set objAcc = CreateObject("Access.Application")
 
objAcc.OpenCurrentDatabase("C:\Temp\MyDb.mdb") 
 
objAcc.Run("Hi")
 
objAcc.Quit
Set objAcc = Nothing
 
Upvote 0
Hi Boblarson,

Thank you so much for your reply, The code is working fine.

Is there a way to call the macro without creating an object im uding an ADODB connection to connect to Access so i thought there might be some other way like using the Command.execute funtion or something.

Im a newbie to access any advice would be appreciated.
 
Upvote 0
No, you must create the object, but if you need it to stay open you can release the object by using

objAcc.UserControl = True

then the code is completely released from it and you can set it to nothing and not affect it. If you don't need that but need it to finish the macro before closing, you can probably use DoEvents to let it do it first.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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