VBA code question

G

Guest

I am trying to create code that will open a specific excel spreadsheet and
then run the macro I created in the spreadsheet. This should happen once I
click a button in Access.

This is similar to the autostart option in the Output To Macro in Access
except I also want to run a macro in Excel once the spreadsheet is opened.

Is this possible?

Thanks in advance.
 
H

Hoodwink

Try using this code in the button click event:

Dim excelApplication As Excel.Application
Set excelApplication = New Excel.Application
excelApplication.Visible = True
excelApplication.Workbooks.Open ("C:\filepathhere\spreadsheet.xls")
excelApplication.Workbooks.Application.Run ("Macro1")
you have to set a reference to the Excel object library first
 
L

Larry Daugherty

I know you're trying to get this done from Access but your issue is really
in Excel.

In this case, it doesn't require any Excel code in Access. Put your Excel
macro into the Workbook_Open() event of your target workbook. Promise not
to tell the Excel folks we answered it over here in Access :-()

HTH
 
L

Larry Daugherty

Ooops! The Workbook_Open() part is true but I didn't answer part of your
question. Look up Automation and Understanding Automation in Access Help.
It gives examples of declaring and setting objects using Excel.

HTH
 

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