running excel macro

K

karin

does anyone know how i can run an excel macro from access.
this is what i've tried with no success--it says that i'm trying to use an
undefined object. The excel document is open and I think i've checked all
the appropriate things in the object library...

Dim appExcel As Excel.Application
appExcel.ActiveWorkbook.Application.Run ("DeleteCells")

help?!
kari
 
K

Ken Snell [MVP]

This may get you started:

Dim xls As Object, xwkb As Object
Dim strFile As String, strMacro As String
strFile = "ExcelFilename.xls"
strMacro = "MacroName"
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
 

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