Solved

Saving a file that increments the date in specific format.

Posted on 2013-12-27
5
221 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 39

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 39

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 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