"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:eek:ffice:eek:ffice" /><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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Maybe like this

Code:
Sub CopySheet()
ActiveSheet.Copy
With ActiveWorkbook
    .SaveAs Filename:=ActiveSheet.Name & ".xls"
    .Close
End With
End Sub
 

Javi

Active Member
Joined
May 26, 2011
Messages
440
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><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? “
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

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

Forum statistics

Threads
1,136,644
Messages
5,676,967
Members
419,665
Latest member
allsmilees2

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