Working with Two WorkBooks

D

Donald Lloyd

HI,

I'm a bit mixed up with running macros from other Workbooks.

There are two workbooks open, say Book1 and Book2.
At the end of a session, with Book2 being the active workbook, I want to run
a macro (called, say ShutDown ) in Book1 which will then close Book2. I'm Ok
after that.

If it helps - Book1 is Workbooks(1) and Book2 is Workbooks(2)

Any pointers please ?

regards,
Don
--
 
B

Bob Phillips

Donald,

I am assuming that the call to Shutdown is from a macro in Book2. If so, add
this to your macro in Book2

Application.Run ("Book1!Shutdown")

The shutdown macro would include this line of code

Workbooks("Book2").Close

If you want it to close without saving, precede by

Workbooks("Book2").Saved = True

If you want it to save Book2 without prompting you, precede by

Application.DisplayAlerts = False

and set to True afterwards.

Hop I haven't mixed up Book1 and Book2.
 
D

Donald Lloyd

Nothing mixed up, Bob

That's great. Thank you,

Don

--

Bob Phillips said:
Donald,

I am assuming that the call to Shutdown is from a macro in Book2. If so, add
this to your macro in Book2

Application.Run ("Book1!Shutdown")

The shutdown macro would include this line of code

Workbooks("Book2").Close

If you want it to close without saving, precede by

Workbooks("Book2").Saved = True

If you want it to save Book2 without prompting you, precede by

Application.DisplayAlerts = False

and set to True afterwards.

Hop I haven't mixed up Book1 and Book2.

--

HTH

Bob Phillips

Donald Lloyd said:
HI,

I'm a bit mixed up with running macros from other Workbooks.

There are two workbooks open, say Book1 and Book2.
At the end of a session, with Book2 being the active workbook, I want to run
a macro (called, say ShutDown ) in Book1 which will then close Book2.
I'm
 
D

Donald Lloyd

Just a further small query re:-
Application.Run("Book1!Shutdown")
What would the format be if referring to Book1 by its Index ?

regards,
Don

--

Bob Phillips said:
Donald,

I am assuming that the call to Shutdown is from a macro in Book2. If so, add
this to your macro in Book2

Application.Run ("Book1!Shutdown")

The shutdown macro would include this line of code

Workbooks("Book2").Close

If you want it to close without saving, precede by

Workbooks("Book2").Saved = True

If you want it to save Book2 without prompting you, precede by

Application.DisplayAlerts = False

and set to True afterwards.

Hop I haven't mixed up Book1 and Book2.

--

HTH

Bob Phillips

Donald Lloyd said:
HI,

I'm a bit mixed up with running macros from other Workbooks.

There are two workbooks open, say Book1 and Book2.
At the end of a session, with Book2 being the active workbook, I want to run
a macro (called, say ShutDown ) in Book1 which will then close Book2.
I'm
 

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