Working with Two WorkBooks

  • Thread starter Thread starter Donald Lloyd
  • Start date Start date
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
--
 
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.
 
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
 
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
 
Back
Top