Code to create a copy of the workbook I'm in with a new name

WStockel

New Member
Joined
May 30, 2020
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I want to make a copy of the workbook I'm in to a new workbook.
Then save this new workbook in the same unknown location that the original workbook is in.
I want to name the new workbook "NASCAR " & worksheet("Menu").cells(1,1).value in the old workbook.
Then I want to clear some ranges of cells on a few of the worksheets in the new workbook.
Then open the new workbook and close the old workbook.
I'm not sure all this is possible.
 

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.
So I figured out how to make the new workbook with the file name I wanted.
But how do I clear some sheets in the new workbook from a macro in the old workbook?
VBA Code:
Dim sFullName As String ' worksheet
Dim nShtName As String

nShtName = "\" & "NASCAR " & CBYear.Text & ".xls"
sFullName = ThisWorkbook.Path & nShtName
ActiveWorkbook.SaveCopyAs sFullName


This is the worksheet I want to clear but I want to do it in the new workbook
Worksheets("Players").Range("A2:D10").Clear
 
Upvote 0
I figured it out.
VBA Code:
    Set wb = Workbooks.Open(nShtName)
    
    ' update header on the Menu sheet with new year
    wb.Worksheets("Menu").Cells(1, 1).Value = CBYear.Text ' header on Menu sheet with new year
    
    ' Week number to 1
    wb.Worksheets("Menu").Cells(6, 4).Value = 1
    
    ' erase players page
    wb.Worksheets("Players").Range("A2:E41").Clear
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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