Solved

Saving a file that increments the date in specific format.

Posted on 2013-12-27
5
222 Views
Last Modified: 2014-01-02
How can this be changed to increment the date into the filename?
Desired filename and format: Bruce Shortage Report ddmmyy.xlsx
can mm be abbreviated month like Dec, Nov, ?
I get sick of having to go out to the W drive and adding it everyday..  thanks -R-

Sub SaveFileToWDrive()
'
    ChDir "W:\Holland\rrw5"
    ActiveWorkbook.SaveAs Filename:= _
        "W:\Holland\rrw5\Bruce Shortage Report.xlsx", FileFormat:= _
        xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWorkbook.Close
    MsgBox ("File Saved to W:\Holland\rrw5\ [        ]")
    
End Sub

Open in new window

0
Comment
Question by:RWayneH
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 39742284
Sub SaveFileToWDrive()
Dim FName As String
'
 FName = "W:\Holland\rrw5\Bruce Shortage Report "
 FName = FName & Format(Date, "ddmmmyy") & ".xlsx"
    'ChDir "W:\Holland\rrw5"
    ActiveWorkbook.SaveAs Filename:= _
        FName, FileFormat:= _
        xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWorkbook.Close
    MsgBox ("File Saved to " & FName)
    
End Sub

Open in new window

0
 

Author Comment

by:RWayneH
ID: 39742335
Thanks, one more quick question on the date format, if they wanted to put a - or dot in the date would this work?

FName = FName & Format(Date, "dd'."mmm'."yy") & ".xlsx"  I know someone is going to ask to chg that around.  Thanks. -R-
0
 
LVL 40

Expert Comment

by:als315
ID: 39742376
No, you can use non reserved symbols inside string:
Format(Date, "dd-mmm-yy")
http://msdn.microsoft.com/en-us/library/office/gg251755.aspx
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 39743337
If you really wanted this sorted better, I'd use "yyyy-mm-dd".

Scott C
0
 

Author Closing Comment

by:RWayneH
ID: 39752937
Thanks. -R-
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

This article will show you how to use shortcut menus in the Access run-time environment.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

838 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