+ Reply to Thread
Results 1 to 11 of 11

Thread: VBA Save w/ date showing Wrong Date

  1. #1
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    VBA Save w/ date showing Wrong Date

    I am trying to safe a file including todays date. The macro will exacute, but the date is wrong and strung together
    i.e. Vendor Validation Report 40644.xls \

    I have tried using & Format(NOW, MM - DD - YY) & ".xls", as well as & Format(Date, MM - DD - YY) & ".xls"

    niether seem to pull the correct date or format it in "MM-DD-YY" format

    Any Tips - I am very new to VBA

    thanks


    You can View my code below:

    Sub SAVE_TEST()
    '
    ' SAVE_TEST Macro
    '
    '
    '

    ChDir "C:\~VENDOR_VALIDATION"
    ActiveWorkbook.SaveAs Filename:= _
    "C:\~VENDOR_VALIDATION\Vendor Validation Report" & Format(Date, MM - DD - YY) & ".xls", FileFormat:=xlExcel8, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False

    With ActiveSheet
    Range("A1").Select
    End With

    End Sub

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: VBA Save w/ date showing Wrong Date

    hi,
    try this
    '
    "C:\~VENDOR_VALIDATION\Vendor Validation Report" & Format$(Date, "dd-mmm-yyyy")
    '
    Regards, John

  3. #3
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: VBA Save w/ date showing Wrong Date

    Nope that doesnt work either. it generate's the same bogus date.....

  4. #4
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    657

    Re: VBA Save w/ date showing Wrong Date

    HI,


    You should use the forum format for the code tags.
    Here is your code which i added a correction too.
    You can however record a macro to see how to format the SaveAs file.

     Format(Date, "MM - DD - YY")''' note the " " "
    Sub SAVE_TEST()
    '
    ' SAVE_TEST Macro
    '
    '
    '
    
    
    ChDir "C:\~VENDOR_VALIDATION"
    ActiveWorkbook.SaveAs Filename:= _
    "C:\~VENDOR_VALIDATION\Vendor Validation Report\" & Format(Now, "MM - DD - YY") & ".xls"
    
    With ActiveSheet
    Range("A1").Select
    End With
    
    End Sub
    Last edited by Charles; 04-11-2011 at 04:03 PM. Reason: corrected code to shorter code
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  5. #5
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: VBA Save w/ date showing Wrong Date

    These do not work, I have tried so many variations, but none of them work. I am using Excel 2007, could this be part of the issue?

    In addition, nobody has included the code for the file extention type. and if I dont script the excel format type (i.e. 97-2003 or 2007) it will save but I loose all the formatting on save and when I open it kicks me a warning that the file is not in the format of its listed extention....

  6. #6
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    657

    Re: VBA Save w/ date showing Wrong Date

    Hi,

    It might help if we can see a copy of your workbook. All of the codes that were posted worked.
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  7. #7
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: VBA Save w/ date showing Wrong Date

    I have attached the Workbook I am attempting to save with the current date, and I attached the PERSONAL.XLS that houses all the code. Hope this helps
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor Charles's Avatar
    Join Date
    02-10-2004
    Location
    Biloxi
    MS-Off Ver
    Windows 7, Excel 2003,2007 & Mac2011
    Posts
    657

    Re: VBA Save w/ date showing Wrong Date

    Hi,

    The following is the code I used for my test.

    ' this is the saved as name Copy of North Vendor Validation Report 04 - 13 - 2011
    ChDir "Z:\MacExcel\ExcelFiles"
        ActiveWorkbook.SaveAs Filename:= _
            "Z:\MacExcel\ExcelFiles\Copy of North Vendor Validation Report " & Format(Now, "MM - DD - YYYY") & ".Xls" _
            , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
    This is the result
    Copy of North Vendor Validation Report 04 - 13 - 2011

    Try the following code in your Personal code Module7

    Sub SAVE_TO_C_DRIVE()
    '
    ' SAVE_TO_C_DRIVE Macro
    '
    ' Keyboard Shortcut: Ctrl+e
    '
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    
    Application.Run "PERSONAL.XLSB!FINAL_EDIT"
    Application.Run "PERSONAL.XLSB!REMOVAL_BLANKET_REMOVE_BY_FILTER"
    Application.Run "PERSONAL.XLSB!STATUS_REMOVE_BY_FILTER"
    Application.Run "PERSONAL.XLSB!FREEZE"
    
        Cells.Select
        Cells.EntireColumn.AutoFit
        Range("A1").Select
    
    
    '******************************************
        'WHEN VENDOR SHAEPOINT IS READY ACTIVATE
    'ChDir "C:\~VENDOR_VALIDATION"
        'ActiveWorkbook.SaveAs Filename:= _
            '"Z:\North Vendor Validation Report.xls", FileFormat:=xlExcel8, _
           ' Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
            'CreateBackup:=False
    '******************************************
    
        ChDir "C:\~VENDOR_VALIDATION"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\~VENDOR_VALIDATION\North Vendor Validation Report " & Format(Now, "MM - DD - yyyy") & ".xls", FileFormat:=xlExcel8, _
            Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
            CreateBackup:=False
    Application.ScreenUpdating = True
            
            With ActiveSheet
            Range("A1").Select
            End With
    
    Application.DisplayAlerts = True
    
    End Sub
    Charles

    There are other ways to do this, this is but 1 !
    Be Sure you thank those who helped.
    IF YOU'RE SATISFIED BY ANY MEMBERS RESPONSE TO YOUR ISSUE PLEASE USE THE STAR ICON AT THE BOTTOM LEFT OF THE POST UNDER THEIR NAME.

  9. #9
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: VBA Save w/ date showing Wrong Date

    I completly belive it is working on other machines, but not only have I tried this exact script, I retried it and still it doesnt work, it kicks this invalid dummy date. Is this a problem with my excel system referance?

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: VBA Save w/ date showing Wrong Date

    hi CBG,
    it works for me too! just for a test, run with this code and see if it works for you with a test file.
    Sub Button2_Click()
    ActiveSheet.Copy
    
         'Saves filename as value of A1 plus the current date
         
        Dim newFile As String, fName As String
         ' Don't use "/" in date, invalid syntax
        fName = Range("A1").Value
         'Change the date format to whatever you'd like, but make sure it's in quotes
        newFile = fName & "Sheet1 - " & Format$(Date, "dd-mmm-yyyy")
         ' Change directory to suit your PC, including USER NAME
        ChDir _
        "C:\users\john\Desktop"
        ActiveWorkbook.SaveAs Filename:=newFile
    End Sub
    Regards, John

  11. #11
    Registered User
    Join Date
    04-07-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: VBA Save w/ date showing Wrong Date

    John:

    That worked, Why is it that this code worked and none of the other variations did?

    Thanks for the help everyone...

    Brad

+ 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.2.0