Code for running an excel macro from access

M

Matt

I am in Access and want to write a line that will automatically execute VB
code that is attached to an Excel workbook. I think I am suppose to begin
with Set ExcelWorkbook = GetObject("c:ExcelFile.xls"), the question is what
would I do next.

Thanks,
Matt
 
N

Norman Yuan

Try this:

Dim xls As Excel.Application
Dim wk As Excel.Workbook

Set xls=New Excel.Application
xls.Visible=true

Set wk=xls.Workbooks.Open("C:\TempMyFile.xls")
xls.Run ".....<some arguments, like macro name, see excel help...>"

wk.Close True 'Save changes made by macro
xls.Quit

Set wk=Nothing
Set xls=Nothing


If the Excel is already open and you want to use that Excel instance then
you can

Set xls=Getobject(, Excel.Application") 'To get reference to Excel
Application, then call Application.Run() method.
 
Top