Copy open workbook to same folder dir with date amended to name

IIII

New Member
Joined
Jan 26, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
Hi All - as it states in the heading, I'm looking to either amend the code below or obtain a new on where I can copy the workbook I have open to the same folder but with the Week ending date (Sunday) added to the end of the file name.

I found this code (Credit: @swapnilk) that gets me going into the right direction but I just need it to save and do the above without prompting. Hope this makes sense, otherwise please let me know if more info is required. Thanks all.

VBA Code:
Sub SaveCopy()
    'Declare a variable to hold the current workbook
    Dim wb As Workbook
    'Set the variable equal to the current open workbook
    Set wb = ActiveWorkbook
    
    'Prompt the user for the location to save the copy of the workbook
    Dim savePath As String
    savePath = Application.GetSaveAsFilename( _
        InitialFileName:=wb.Name, _
        FileFilter:="Excel Files (*.xlsx), *.xlsx")
    
    'Save a copy of the workbook to the specified location
    wb.SaveCopyAs savePath
End Sub

(y)
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this macro:
VBA Code:
Public Sub Save_As_New_Workbook_With_Date()

    Dim nextSunday As Date
    Dim p As Long
    Dim newFullName As String
        
    nextSunday = Date + 8 - Weekday(Date)
    
    With ActiveWorkbook
        p = InStrRev(.FullName, ".")
        newFullName = Left(.FullName, p - 1) & Format(nextSunday, " YYYY-MM-DD") & Mid(.FullName, p)
        .SaveCopyAs newFullName
    End With

End Sub
 
Upvote 0
Solution
Try this macro:
VBA Code:
Public Sub Save_As_New_Workbook_With_Date()

    Dim nextSunday As Date
    Dim p As Long
    Dim newFullName As String
       
    nextSunday = Date + 8 - Weekday(Date)
   
    With ActiveWorkbook
        p = InStrRev(.FullName, ".")
        newFullName = Left(.FullName, p - 1) & Format(nextSunday, " YYYY-MM-DD") & Mid(.FullName, p)
        .SaveCopyAs newFullName
    End With

End Sub

Thank you @John_w - this works perfectly. Appreciate it! Cheers. 🍻
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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