#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Location
    Hartford, Connecticut, USA
    Posts
    12
    Rep Power
    0

    Copy an Excel file adding yesterday's date


    I want to copy an excel file and rename it with yesterday's date. Such as test 02-22-12.xlsx

    I have most of the code working, but for some reason it names it test 00-22-12.xlsx I don't know why it is using 00 for the month... Maybe a more advanced VBA user can assist. I am using Visual Basic 2010.

    Code:
    Module test 
    Sub Main() 
    'Copy and Rename the report' 
    My.Computer.FileSystem.CopyFile("C:\Test.xlsx", "C:\Test " & Format(DateAdd("d", -1, Today()), "mm-dd-yy") & ".xlsx", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing) End Sub End Module
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2009
    Location
    Hartford, Connecticut, USA
    Posts
    12
    Rep Power
    0
    I figured it out myself, but decided to keep it on here to help someone else....

    Code:
    Module test
    
        Sub Main()
    Dim yourdate As Object 
    'Date format' 
    yourdate = Format(DateAdd("d", -1, Today()), "MM-dd-yy") 
    'Copy and Rename the report' 
    My.Computer.FileSystem.CopyFile("C:\Test.xlsx", "C:\Test " & yourdate & ".xlsx", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.DoNothing)
    
    End Sub
    End Module

    Comments on this post

    • medialint agrees : thanks for following up

IMN logo majestic logo threadwatch logo seochat tools logo