Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Amend Save File code

Posted on 2012-09-17
2
Medium Priority
?
295 Views
Last Modified: 2012-10-09
Hi,

I have the below which saves as todays date, i need it amended so it saves as yesterdays date and it must account for weekends.

So saving today would create

14/09

and saving tomorrow will create

17/09

Thanks
Seamus


    Strpath = "xyz:\Ldn\BOBPS\BOBPSControl\Rep\Match Stats\GLA & SGP New Reporting\Daily Intellimatch File"

    strFileSaveName = "" & Format(Date, "yyyymmdd") & ".xls"
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=strFileSaveName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
0
Comment
Question by:Seamus2626
2 Comments
 
LVL 12

Expert Comment

by:Seaton007
ID: 38406234
0
 
LVL 11

Accepted Solution

by:
ScriptAddict earned 1500 total points
ID: 38406278
You are going to need to edit date.  to a new date based on weekday.  

checkout the date(year,month,day) command and the weekday(serial number, return type) commands.

I'd assume it would be something like this:

dim d1 as date 

Strpath = "xyz:\Ldn\BOBPS\BOBPSControl\Rep\Match Stats\GLA & SGP New Reporting\Daily Intellimatch File"

If Weekday(Date, 1) = 2 Then
'MsgBox "monday"
 d1 = Date - 3

Else
'MsgBox "Not monday"
d1 = Date - 1
End If

    strFileSaveName = "" & Format(D1, "ddmm") & ".xls"
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:=strFileSaveName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False 

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question