Code for running an excel macro from access

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

Guest

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
 
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.
 

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

Back
Top