Copying a worksheet from a workbook into another workbook

pincivma

Board Regular
Joined
Dec 12, 2004
Messages
206
I found this Excel code on the internet. It works fine. However there is a problem with the code. When I run the code a second time, I get a message that says I cannot save this workbook with the same name. Is there a code that I can use that can override the Workbook named Marios sales results. Or instead of adding a workbook is there a way to call a workbook on the 4th line of code??? Thanks

Sub SaveAsMariosSalesResults()
Application.DisplayAlerts = False
ThisFile = Sheets("Commission Table").Range("V16").Value
Set wb = Workbooks.Add

ThisWorkbook.Activate
Sheets("Mario").Copy Before:=wb.Sheets(1)
wb.Activate
wb.SaveAs Filename:=ThisFile, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Change

Code:
Set wb = Workbooks.Add

to

Code:
Set wb = Workbooks.Open(ThisFile)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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