"Excel Vba" I’m need help with a copy sheet code!

Javi

Active Member
Joined
May 26, 2011
Messages
440
I have a workbook with many sheets one of the sheets is a Pivot Table. I would like to give the user the option to create a new sheet with the pivot table sheet and the sheet that contains its source data only.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
This would allow them to continue to work without the large workbook needing to be open. This code will be run from the pivot table sheet.
<o:p> </o:p>
I would appreciate any assistance with this code.
<o:p> </o:p>
Thank you.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Maybe like this

Code:
Sub CopySheet()
ActiveSheet.Copy
With ActiveWorkbook
    .SaveAs Filename:=ActiveSheet.Name & ".xls"
    .Close
End With
End Sub
 
Upvote 0
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
<o:p> </o:p>
The code worked with a few exceptions,

I would like to leave the file that creates open.
<o:p> </o:p>
When you open a file that creates it gives the following error.
<o:p> </o:p>
“The file you were trying to open, “ filename .xls” is in a different format than specified by the file extension. Verify that the file is not corrupt and is from a trusted source before opening the file. Do you want to open the file now? “
 
Upvote 0
Try

Code:
Sub CopySheet()
ActiveSheet.Copy
ActiveWorkbook.SaveAs Filename:=ActiveSheet.Name & ".xlsx", FileFormat:=51
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,687
Members
452,938
Latest member
babeneker

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