Call macro in other sheet

T

Tomas Stroem

I have a Master file containing a macro that opens a number of other
workbooks, collects data and the creates statistics from this retreived data,
work well. Now I need to create some statistics in on of the workbooks that I
open from my Master. In this Slave file I have the macro that I want to run,
but only when the Master is running. How can i call the macro in the Slave
worksheet from the code in the Master macro.

Greatful for all help!
 
T

Tomas Stroem

Per,
Works partially. but nor quite.
The result now is this, Macro Error 1004: "Can not find the macro
"Statistics" in file..."

Macro name is correct as well as file name, any idea of more adaptions
needed??
 
J

Jacob Skaria

When you have a space in the workbook name add a single quote. Try the below.

Application.Run ("'Supplier Total.xls'!Statistics")

If this post helps click Yes
 
D

Dave Peterson

This was saved from a post for a similar question. You'll have to change the
workbook name from personal.xls to the real name.

Dim pWkbk as workbook
set pwkbk = workbooks("Personal.xls")
application.run "'" & pwkb.name & "'!macronamehere", "parm1", "parm2"

or if you're returning a value from a function:

dim res as string 'or variant or long or ...
res = application.run("'" & pwkb.name & "'!macronamehere", "parm1", "parm2")

You could also create a reference to this personal.xls workbook and call it just
like it was built into excel.

Tools|references
(but give the personal.xls's project a nice unique name (not VBAProject).

ps.

If you're using a function living in personal.xls inside a cell:
=personal.xls!functionnamehere(a1,b1,c1)

or save the file as an addin (*.xla) and use it in the cell like it's built into
excel:
=functionnamehere(a1,b1,c1)
 

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