Naming convention for a variable "Book1" while copying sheets
When you execute the Add method of the Workbooks collection, set a variable to its return value. Then you can keep the workbook object in memory, and refer to it that way
Original code
Workbooks.Ad
Windows("ps").Activat
Sheets("Environment").Selec
Sheets("Environment").Copy Befo=Workbooks("Book1").Sheets(1
Windows("ps").Activat
Sheets("CT").Selec
Sheets("CT").Copy Befo=Workbooks("Book1").Sheets(1
Recommended changes
dim wbkNew as Workboo
set wbkNew = Workbooks.Ad
Windows("ps").Activat
Sheets("Environment").Selec
Sheets("Environment").Copy Befo=wbkNew.Sheets(1
Windows("ps").Activat
Sheets("CT").Selec
Sheets("CT").Copy Befo=wbkNew.Sheets(1
And consider this code to eliminate the whole "Select" and "Activate" recorded macro programming
dim wbkPs as Workbook, wbkNew as Workboo
dim shtEnvironment as Sheet, shtCT as Shee
Application.ScreenUpdating = False ' This will make it run faster, and your users won't see what's happening
set wbkPs = Workbooks("ps"
set shtEnvironment = wbkPs.Sheets("Environment"
set shtCT = wbkPs.Sheets("CT"
set wbkNew = Workbooks.Ad
shtEnvironment.Copy Befo=wbkNew.Sheets(1
shtCT.Copy Befo=wbkNew.Sheets(1
Application.ScreenUpdating = True ' Refresh the screen
I hope that helps
-Brad
|