Run Excel Macro from Access

B

Bruce

Essentually I am running MS requry macros to my database. Instead of running
the refresh from Excel I am considering doing it from the database.

Is it possible t run an axcel macro from Access?
Can this be done without opening the excel file, or in the backgound?

Bruce
 
K

Ken Snell [MVP]

The EXCEL must be opened by ACCESS (using Automation) in order to run the
macro. Here is some sample code to get you started:


Public Sub RunAnExcelMacro()
Dim xls As Object, xwkb As Object
Dim strFile As String, strMacro As String
strFile = "Ken.xls"
strMacro = "Testing1"
Set xls= CreateObject("Excel.Application")
xls.Visible = True
Set xwkb = xls.Workbooks.Open("C:\" & strFile)
xls.Run strFile & "!" & strMacro
xwkb.Close False
Set xwkb = Nothing
xls.Quit
Set xls = Nothing
End Sub
 

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