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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Change this:
Sheets("Tracking sheet").Copy.UsedRange
to this:
Sheets("Tracking sheet").UsedRange.Copy
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,211,697
Messages
6,103,360
Members
447,861
Latest member
LllopezXC

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
Back
Top