how to run macro of closed excel workbook using VBA

C

Chip Pearson

You need to open the workbook first, then use Application.Run to execute the
macro. E.g.,

Workbooks.Open "C:\path\FileName.xls"
Application.Run "FileName.xls!MacroName"
Workbooks("FileName.xls").Close savechanges:=False

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
T

Tom Ogilvy

If you mean run a macro contained in an open workbook and you want the macro
to draw data from a closed workbook, then you might look as SQL.Request on
Andy Wiggins site (see below)

or look at using ADO from Mr. Erlandsen's site:
http://www.erlandsendata.no/english/vba/adodao/

recent post from Andy Wiggins:

Tom, take a look at SQL.REQUEST, the function Microsoft supplies in its
XLODBC add-in. Not only can you use variable references to get data from
closed workbooks, you can also use it to update values in closed workbooks.

For illustrations on how to get data from closed workbooks see:
http://www.bygsoftware.com/examples/zipfiles/UsingSqlRequest.zip

It's in the "Excel with Access Databases" section on page:
http://www.bygsoftware.com/examples/examples.htm

This workbook demonstrates how to get data direct from an MS Access table,
or from an open or closed MS Excel workbook using the workbook function
SQL.REQUEST.

Recently updated to show the use of SQL.REQUEST in the same workbook.

The code is open and commented.


--

Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"
 

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