Save current file to include date of current week Saturday?

NormChart55

New Member
Joined
Feb 22, 2022
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
Hello - I have this code saving my file, but I need to tweak it so that the date is for the Saturday of the current week and cannot find a solution. Hopefully there is a simple one. Any thoughts?


VBA Code:
Dim Path As String
Dim Filename As String
Dim dt As String
user = Environ("Username")
Desktop = "C:\Users\" & user & "\Desktop\"

dt = Format(CStr(Now), "yyyy_mm_dd")

    Path = "C:\Users\username\Desktop\"
    Filename = "Template"

On Error Resume Next

  ActiveWorkbook.SaveAs Filename:=Desktop & Filename & " " & dt & ".xlsm", FileFormat:=52
 

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.
Use this for your "dt" calculation:
VBA Code:
    dt = Format(Date + 7 - Weekday(Date, vbSunday), "yyyy_mm_dd")
 
Upvote 0
Solution
thanks, this worked as intended. Very much appreciated.
Use this for your "dt" calculation:
VBA Code:
    dt = Format(Date + 7 - Weekday(Date, vbSunday), "yyyy_mm_dd")
Is there a way to adjust that to Monday of current week for a different file? I played around with changing the + 7 to a minus 7 and adjusted vbSunday to Tuesday, but it goes to the past weeks date. If I leave the +7 it does the Monday for the next week and not current.
 
Upvote 0
Is there a way to adjust that to Monday of current week for a different file? I played around with changing the + 7 to a minus 7 and adjusted vbSunday to Tuesday, but it goes to the past weeks date. If I leave the +7 it does the Monday for the next week and not current.
Take a look at the link I provided, where you can choose a different day for the start of the week, and play around with it.
Off the top of my head, I am not sure if you might have to use an IF to check to see if you are before/after the date already (you might need to do one calculation if it before the weekday, and another if it is after it.
 
Upvote 0
Take a look at the link I provided, where you can choose a different day for the start of the week, and play around with it.
Off the top of my head, I am not sure if you might have to use an IF to check to see if you are before/after the date already (you might need to do one calculation if it before the weekday, and another if it is after it.
thanks again, hope you have a wonderful day
 
Upvote 0
You are welcome.

If you have any issues, show us what you tried, and a few example of different scenarios and what you want to return for each one.
 
Upvote 0

Forum statistics

Threads
1,226,115
Messages
6,189,053
Members
453,522
Latest member
Seeker2025

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