Thread: Macro help
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Macro help

Chuck,

You're welcome. I'm sorry I didn't finish my post before you posted this
thread. I was preparing some simplified code to address your other concern.
Fact is, while using the macro recorder to create code, it's notoriously
inefficient at best. Here's two procedures that do what you want as I
understand your task. It assumes you are copying the sheets to a new wbk as
stated, even though your code only copies columns A:P.

Use this one if the source wbk contains more sheets than you want to copy.
You must manually group the sheets to copy. You do that by Ctrl+ select the
tab of each sheet.

Sub CopyMySheets1()
' Copies user-selected sheets to a new wbk,
' then saves the wbk to a specified folder,
' with a specified filename.

Dim sPath As String

sPath = "I:\Accounts\Active Accounts\Office Depot\Posted Monthly Margin
Report\"

'copy to new wbk
ActiveWindow.SelectedSheets.Copy

'the new wbk is now active so save as
ActiveWorkbook.SaveAs fileName:=sPath & "Office Depot.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub


Use this one if you want to copy all the sheets in the active wbk.

Sub CopyMySheets2()
' Copies all sheets in the active wbk to a new wbk,
' then saves the wbk to a specified folder,
' with a specified filename.

Dim sPath As String

sPath = "I:\Accounts\Active Accounts\Office Depot\Posted Monthly Margin
Report\"

'select all sheets
ActiveWorkbook.Sheets.Select

'copy to new wbk
ActiveWindow.SelectedSheets.Copy

'the new wbk is now active so save as
ActiveWorkbook.SaveAs fileName:=sPath & "Office Depot.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

End Sub

Enjoy!
Regrds,
Garry