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.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

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,344
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,003
Messages
5,834,828
Members
430,324
Latest member
bosphoruskid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top