Running a sub in a different workbook from a sub in this workbook?

R

R

I have a workbook called SAMMY with a worksheet called HOURS. I have
written a VBA sub that manipulates data on this worksheet. The VBA sub
is called hx. In the middle of hx, I need to call up a VBA MACRO from
the (sometimes closed and sometimes open) workbook called FRED, which
has a worksheet called ORDER. The MACRO is currently execured with a
button on FRED_ORDER that ties to the Macro:
FRED_ORDER.xls!order.order

So how do I invoke this Macro from the middle of the sub "hx" on
SAMMY?

ONE EXTRA IMPORTANT NOTE****:
The Macro FRED_ORDER.xls!order.order is completely dependant upon the
cursur being on cell A40 on the ORDER sheet in the FRED workbook. If
the active cell is not A40 on this sheet/workbook then this Macro
won't work (since it needs to "read" the A40 data to determine the
next action. So, when I invoke the macro from the SAMMY_HOURS_hx code
I need to also some how tell the vba code to get on cell a40 first,
before running the order.order, since the order.order macro ASSUMES
that one is already there when one runs it from FRED. Whew, that is
confusing! I hope it makes sense to one of you genuises!

Thnks in advance for the help. I am new to VBA and I am really
confused about how to do this!
 
M

Myrna Larson

Just a comment on the part quoted below. That macro isn't written correctly,
then. It shouldn't refer to ActiveCell or Selection. If you need to work with
cell A40 specifically, the code should say, for example,

Range("A40").Offset(1,0)

not

ActiveCell.Offset(1,0)

If you can't correct that, then your code must open FRED_ORDER.xls, activate
the Order sheet and select cell A40. Only after doing that can you call the
macro in that workbook.

As for the command to run it, look at the Application.Run statement in Help.
It will show you the syntax.
 

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