Saving Filename as Week Number and Date on Friday

Squreshi

New Member
Joined
Dec 17, 2017
Messages
6
Hi, I need to save a file (every week) in excel vba code with a file name which looks like this: "book1.W23.Dec15.xlsx". This file is saved during the week on any day of the week. Here the Week number needs to be a fiscal week number where the year starts on July 1 and ends on June 30th and then "Dec15" will be the date on each Friday of that particular week. The steps as I can figure out will be to see the current date with Now(), then extract the corresponding week number and then the date on Friday but I keep on messing this up. Also I cannot seem to figure out how can I set the year to start from July 1 from the default Jan 1. Can you please help. Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Apologies, forgot to mention that my week starts on Sunday, being in middle east and I am using excel 2013. Thanks
 
Upvote 0
Okay so this is the code that I came up after going through various resources on web. I just need a senior member to do a helpful review of this code in sense if i am missing someting. Also the intention here is to save in the same directory where the active workbook was opened from. Thanks.

'Saving the file in the same directory with week and date


Dim WeekNumber As Integer
Dim LastFriday As Date
Dim NameToSave As String




WeekNumber = Int((((Now() - DateSerial(2017, 7, 2) + 6) / 7) + Abs(Weekday(Now()) = Weekday(DateSerial(2017, 7, 2)))) - 1)
LastFriday = Int(Now() - Weekday(Now()) - 1)
NameToSave = "WIP.W" & WeekNumber & "." & Format(LastFriday, "mmmdd") & ".xlsx"


ActiveWorkbook.SaveAs Filename:=NameToSave, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,741
Members
449,050
Latest member
excelknuckles

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