+ Reply to Thread
Results 1 to 12 of 12

Macro to Save As a file with a date in dd-monthname-yyyy

Hybrid View

  1. #1
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Thumbs up Macro to Save As a file with a date in dd-monthname-yyyy

    Hi

    Can you suggest me a macro which will save a new workbook created using a macro in this particular format:

    "Filename dd-monthname(3digits only)-yyyy"

    Example: "Alarm Logs 16-Mar-2012"

    If the month name is not possible for three digits, it can be as "Alarm Logs 16-March-2012" but the capital letter for month is important.


    Any help would be appreciated.

    Thank you in advance
    Last edited by witcomm; 03-16-2012 at 02:31 AM. Reason: prefix change

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    give this a shot

    ActiveWorkbook.SaveAs Filename:="Alarm Logs " & Format(Date, "dd-mmm-yyyy") & ".xlsx"
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    I tried it but actually the file has to be saved in this path: (goth this using record macro option)

    ActiveWorkbook.SaveAs Filename:= _
    "C:\Documents and Settings\username\Desktop\Alarm Logs 16-Mar-2012.xlsx", _
    FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

    so when i replace the above statement as below, i am getting compile error (expecting end of statement):

    ActiveWorkbook.SaveAs Filename:= _
    "C:\Documents and Settings\dinesh.gundu\Desktop\"Alarm Logs " & Format(Date, "dd-mmm-yyyy") & ".xlsx"", _
    FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

    Thanks for the quick response

    P.S: where is the star to click? i am new to this forums :D

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    try this, no need for the second quote before Alarm Logs.

    ActiveWorkbook.SaveAs Filename:=""C:\Documents and Settings\dinesh.gundu\Desktop\Alarm Logs " & Format(Date, "dd-mmm-yyyy") & ".xlsx"
    and the star button is to the bottom left of a post.

    hope this works for you.

  5. #5
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    awesome.... thank you so muchhh....

    one more final thing... if the want to activate this newly created sheet, what should i do? the changes i need you to do is in bold italics

    please refer this code:

    Workbooks.Add
    ActiveWorkbook.SaveAs Filename:= _
    "C:\Documents and Settings\user\Desktop\Alarm Logs 16-Mar-2012.xlsx", _
    FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Windows("Alarm Logs.xlsm").Activate 'source file from where i copy stuff
    Cells.Select
    Selection.Copy

    Windows(" Book1.xlsx" ).Activate
    ActiveSheet.Paste
    Application.CutCopyMode = False

  6. #6
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    try something like this:

        Dim NewBook As Workbook
        Set NewBook = Workbook.Add
        NewBook.Activate

  7. #7
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    I have tried it.... i got the output as, compile error (Object required) for the second line of ur code...

  8. #8
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    sorry i missed an s

        Dim NewBook As Workbook
        Set NewBook = Workbooks.Add
        NewBook.Activate

  9. #9
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    Perfect

    Thank you so much

  10. #10
    Registered User
    Join Date
    02-20-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    I tried this but I kept getting this error... Compile Error, can't find project or library. HELP

    Sub SaveAs()
    
            ChDir "D:\My Documents\Francis Work Files\Suntrac Traders Database"
       'Retrieve file name to use for Save
       fileSaveName = Application.GetSaveAsFilename( _
       fileFilter:="Excel Files (*.xlsm), *.xlsm")
       
    
          
          'If user specified file name, perform Save and display msgbox
          
       If fileSaveName <> False Then
          ActiveWorkbook.SaveAS Filename:=fileSaveName, FileFormat:=52
          
          MsgBox "Save as " & fileSaveName
       End If
       Sheets("Consolidated").Select
        Range("A1").Select
    
    End Sub
    Last edited by arlu1201; 02-21-2013 at 02:10 AM.

  11. #11
    Registered User
    Join Date
    02-21-2012
    Location
    went ighboado
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    @Gab: Brief me what you are trying to accomplish... so i may provide you a simpler approach or correct.

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro to Save As a file with a date in dd-monthname-yyyy

    Gabkrys,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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