Can you save a file with yesterday's date in the file name?

option

Registered User.
Local time
Today, 08:48
Joined
Jul 3, 2008
Messages
143
So I have the following code to save a file with today's date, but can that be changed to save with yesterday's date or even the date from 2 days ago? Just wondering because I have a task that requires saving a file name with Friday's date when you run it on Monday.
Code:
objWord.Application.ActiveDocument.SaveAs "K:\Letters\270_30_DelqLetters\PrintCenter" & Format(Date, "mmddyy") & ".doc"

Any ideas?

Thanks!!!:D:D
 
Make a variable of a date/time data type and use the below.


variable=Date()-1
 
I had something similar that I did once with a zip file. I used:

strFilename = CStr(Format(Date, "mmddyy")) & "MAIN.zip"

Do you mean If today is Monday, save it as Fridays date?
 
Do you mean If today is Monday, save it as Fridays date?

Yes, exactly. I have a function that downloads a file from Friday, but I can't run it until Monday. The file that is downloaded needs to have Fridays date at the end of it, which we're doing manually. Since everything up to that point (which is the final step) is automated, I'd like to automate that as well to decrease any errors. I know renaming a file is pretty fool proof, but you'd be surprised around here hahaha. +rep for both of you btw!
 
Maybe this will put you in the right direction:

Code:
If Format(Date, "dddd") = "Monday" Then
    MsgBox ("It Is Monday")
Else
    MsgBox ("It's not Monday.")
End If
 
I get where you are going with the message boxes, but I'd like to keep as little interaction as possible with the database. I've tried everything I could think of to subtract 2 days from today's date in code. I appreciate the effort though, thanks! :)
 
Only requires a little change.

Code:
If Format(Date, "dddd") = "Monday" Then
    objWord.Application.ActiveDocument.SaveAs "K:\Letters\270_30_DelqLetters\PrintCenter" _
    & Format(Date - 3, "mmddyy") & ".doc"
Else
    objWord.Application.ActiveDocument.SaveAs "K:\Letters\270_30_DelqLetters\PrintCenter" _
    & Format(Date, "mmddyy") & ".doc"
End If
 
MidMented,
Weekday(Date,2) = 1
would IMHO be slightly better than your format...

Also @Option using a non ISO format is a filename will give you problems I advice you to use an ISO date in your filename either YYMMDD or YYYYMMDD will make your live in filename-land much easier.
 
True

I think the filename should be changed as well. I normally name my files in YYMMDD format. It does make things easier to find. I only made it the same as what they already have.
 

Users who are viewing this thread

Back
Top Bottom