Active sheets

  • Thread starter Thread starter Joe Bannister
  • Start date Start date
J

Joe Bannister

Hello all,

I have a macro that opens a second work book, does
various things and then closes the second workbook. Once
closed does the existing workbook automatically become
the active workbook again as it is the only one now open?

It would seem i have to activate it again by specifying
its name, i'd like to avoid this if possible.

Any help appreciated.

Cheers

Joe
 
Hi Joe
I would suggest you add the following coede to your macro:
sub foo()
Dim old_wbk as workbook
Dim old_wks as worksheet
Set old_wbk = Activeworkbook
Set old_wks = old_wbk.Activesheet

'....your code

old_wbk.activate
old_wks.activate
end sub
 
Heartily endorse this approach. By creating object variables you don't need
to worry about what is active, just refer to the object through that
variable.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
I would say the old workbook automatically becomes the active workbook.


At least in this example:

ActiveWorkbook.close True, SPECName

In this case active workbook (new workbook) is closed and changes are
saved as SPECName, and the old workbook becomes the active workbook.
 
Back
Top