View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JER JER is offline
external usenet poster
 
Posts: 2
Default Naming convention for a variable "Book1" while copying sheets

I have gotten this far in developing a macro for saving
sheets to a new workbook that users will name themselves.
I can not count on the new workbook to be "Book1" all the
time as the user may have one or more new Books (Book1-n)
open and the next book number would be book1-n+1.

So I need to somehow establish a convention to assign a
name to the new book in the following code (in earlier
versions of this saga I was copying only the input cells
to a new book and the solution there was to simply
use "Windows(2)" as the second book. That doesn't work in
this case.)


Sub sheetsavetrialz()
'
'This starts the save process which saves all cells with
required or optional user input in the selected areas to a
new workbook.
'establishes "ps" as the name for the active workbook
ps = ThisWorkbook.Name
Windows(ps).Activate
ActiveWindow.WindowState = xlMinimized

Workbooks.Add
Windows("ps").Activate
Sheets("Environment").Select
Sheets("Environment").Copy Befo=Workbooks
("Book1").Sheets(1)
Windows("ps").Activate
Sheets("CT").Select
Sheets("CT").Copy Befo=Workbooks("Book1").Sheets(1)
....
and on until the desired sheets (selected via a control)
are saved.



THANKS!
JER