copy to new workbook

viper

Active Member
Joined
Feb 15, 2002
Messages
382
I've been searching all my favorite boards and am either using the wrong keywords or whatever.

I'm trying to copy one sheet to a new workbook.

I know this is easy to do but I'm hitting errors like crazy. I've tried using this code.

Code:
wb = Workbooks.Add
Sheets("Tracking sheet").Copy.UsedRange
wb.Range("A1").Paste

Thanks for any help.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Change this:
Sheets("Tracking sheet").Copy.UsedRange
to this:
Sheets("Tracking sheet").UsedRange.Copy
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,057
Office Version
  1. 365
Platform
  1. Windows
viper

Try this.
Code:
Sheets("Tracking sheet").Copy

It should create a new workbook with only th Tracking Sheet in it.

By the way it would help if we saw the rest of your code.:)

And an explanation of what you are trying to do.
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Thanks for the help. Norie that is basically my code. All I'm trying to do is copy the worksheet into a new workbook and then save the new workbook as trackingsheet.xls. I'm doing this in the workbook_beforeclose event. I have a workbook that the user will use to enter days employee's miss due to late, etc. The workbook is set up to paste the user's name, time of change, and cells changed to the tracking sheet. I only want to save the tracking sheet as a reference for all the changes.

So I guess for the entire code I'm trying to write is to copy the worksheet into a new workbook (overwrite each time), and then save the workbook as noted above.
 

viper

Active Member
Joined
Feb 15, 2002
Messages
382
Thanks for the help on this. I now have it working as I want and the complete code is listed below. I was running into trouble coping a hidden worksheet.

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
   'turn off alerts
    Application.DisplayAlerts = False
   'unhide sheet to copy
    Sheets("Tracking sheet").Visible = xlSheetVisible
   'copy worksheet
    Sheets("Tracking sheet").Copy
   'save new workbook under new name
    ActiveWorkbook.SaveAs "trackingsheet.xls"
   'save new workbook
    ActiveWorkbook.Close savechanges = True
   're-hide worksheet
    Sheets("Tracking sheet").Visible = xlSheetVeryHidden
   'save primary workbook
    ActiveWorkbook.Save
    
End Sub

Thanks for all the help.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,455
Messages
5,572,235
Members
412,449
Latest member
mdvouf
Top