+ Reply to Thread
Results 1 to 2 of 2

Saveas with previous month in file name

Hybrid View

  1. #1
    Registered User
    Join Date
    02-21-2011
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Saveas with previous month in file name

    Hi All,

    Im trying to use this code with the end result being the saved file will have the previous month (2 digit) at the end of filename eg 11-Test-03.xls. Works with current month but when i try to -1 month all hell breaks loose.
    Any help appreciated. thanks.

    Sub saveas()
    '
    ' saveas Macro
    '
    
    '
        ChDir "C:\Test"
        ActiveWorkbook.saveas Filename:= _
            "C:\Test\11-Test-" & Format(Now, "MM") & ".xls" _
            , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
    
    End Sub
    Last edited by dnyhof; 04-12-2011 at 12:48 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Saveas with previous month in file name

    Public Sub demo()
        ChDir "C:\Test"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Test\11-Test-" & Format(Format(Now, "m") - 1, "0#") & ".xls" _
            , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1