How to run an Excel 2007 macro from a VB program ?

G

Guest

I need to create reports in Excel format, and the easiest way for me to do
that is to have an Excel macro pull the data from the database and use the
data to fill in a pre-formatted sheet that it subsequently saves as a new
workbook. So far so good, I got the macro working and generating the reports.
Now I need to automate those reports in a way that will not require any
human intervention at any stage. I also need to email the reports after Excel
is done generating them.

I'd like to write a VB.NET program that will call the Excel macro (a VBA Sub
in an Excel module), and subsequently email the report.

How can a VB.NET program trigger an Excel VBA macro ?
 
C

Chip Pearson

If you have a reference to the Excel Application object, you can call the
Run method to run a macro in any open workbook. E.g.,

XLApp.Run "BookName.xls!MacroName"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 
G

Guest

Thank you, that's what I was looking for.

Chip Pearson said:
If you have a reference to the Excel Application object, you can call the
Run method to run a macro in any open workbook. E.g.,

XLApp.Run "BookName.xls!MacroName"


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)
 

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