Run Excel Macro from Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top