Consulting

Results 1 to 2 of 2

Thread: Adding MMM-YY to filename

  1. #1

    Adding MMM-YY to filename

    Hi

    I have seen a lot of posts around the net regarding how to datestamp an Excel filename but I haven't yet found anything to specifically stamp it with a supplied variable.

    The scenario is that the macro opens up various files, grabs the data and appends it to another output file.

    I then want to save the input file into an archive folder appending " - MMM-YY" to the filename. The value of "MMM-YY" needs either to be input in a prompt at the beginning of the process or to entered into a cell in the workbook that is running the macro.

    I cannot rely on trying to extract the MMM-YY from today's date as (for instance) we could be in September but the filename needs to be appended with "AUG-12".

    Please can anyone advise how this can be done?

    Thanks

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    [VBA]
    Sub svwb()
    Dim wb As Workbook
    Dim sDate As String
    Dim spath As String
    spath = "C:\"
    sDate = InputBox("Enter the Date for the file prefix in the format MMM-YY")
    'sDate = format(range("A1"), "MMM-YY") <<<<alternative to above assuming that A1 has a date in it
    Set wb = Workbooks("asdf.xlsx") 'assign the workbook to the variable however you wish to
    wb.SaveAs spath & sDate & "-" & wb.Name
    End Sub

    [/VBA]
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

Posting Permissions

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