Retrieve saved workbook according to date

Jackblack1

Active Member
Joined
Feb 10, 2004
Messages
266
Hi All

I have a macro that saves a workbook according to yesterdays date automatically when a button is clicked. The problem is this macro does not exclude weekend dates. I need it exclude weekend dates so that on Monday it is save according to Fridays date.(see macro below)

Then I am trying to create a macro that will go back and retrieve the prior dates saved workbook, this happens each day. One important thing, if it monday then it will retrieve fridays. How can this be done?

sPath = "R:\FACSAPPS\FA\CUS\STL\DIRECT PROGRAM\Exemptive Order\2007\"

If Dir(sPath & Format(Date, "mmm yy"), vbDirectory) = "" Then

VBA.MkDir (sPath & Format(Date, "mmm yy"))
End If

sPath = sPath & Format(Date, "mmm yy") & "\"

sFileName = Format(Now(), "mmddyy") & " -exe.xls"

ActiveWorkbook.SaveAs Filename:=sPath & sFileName, FileFormat:= _
xlExcel9795, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Sorry for the confusion but it is the best I could do explaining this.

Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You may need to consider Holidays as well.

You can change the date format to suit.
Code:
Sub Test()
  Dim thisDate As Date
  'thisDate = Date
  thisDate = #7/16/2007#
  MsgBox "Todays Date: " & Format(thisDate, "mm/dd/yyyy") & vbCrLf & _
    "Minus 1 day but more if on weekend: " & M1OnWeekday(thisDate)
End Sub


Function M1OnWeekday(d As Date, Optional dateFormat As String = "mm/dd/yy") As String
  Dim m1Date As Date
  m1Date = d - 1
  Do Until Not (Weekday(m1Date) = 1 Or Weekday(m1Date) = 7)
    m1Date = m1Date - 1
  Loop
  M1OnWeekday = Format(m1Date, dateFormat)
End Function
 
Upvote 0
Thanks for the reply,

I sorry for not being clear, but the macro is save the report according to a prior (not yesterdays) day. When I click the button it saves it in a folder accoridng to the prior day as the name. I want it to save the prior days date as the name but when saved on monday it saves as fridays date.

The other part of the macro is when I click the button it will open the prior dates report thats name is the prior days date. It will open the report extract some information and close.

I don't know how to program it so that excel will read the name know it is the prior days and open it.

thanks
 
Upvote 0
Then all you have to do is change M1Date=d+1 in the function to M1Date=d.

Then call the function to build the filename something like:
Code:
sFileName = M1Weekday(d, "mmddyy") & " -exe.xls"
Where d is your prior date however you determined that.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,959
Latest member
camelliaCase

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