Copy file and rename it using VB

Posted on 2004-11-08
Last Modified: 2011-08-18

I'd like to copy an existing (*'xls) file from a folder [C:\nbutane\rsview\report\] into the same folder but the new file will be rename.

FileCopy "C:\nbutane\rsview\report\FC Daily Report.xls", "C:\nbutane\rsview\report\FC Daily Report\" & Format(Date - 1, "ddmmmmyyyy") & ".xls"
End Sub

Source (original filename) : FC Daily Report.xls
Target (new filename) : FC Daily Report.xls 07112004.xls

Anyone can verify if the VB code above is correct? Thx.
Question by:ckchew666
    LVL 3

    Accepted Solution


    FileCopy "C:\nbutane\rsview\report\FC Daily Report.xls", "C:\nbutane\rsview\report\FC Daily Report\" & Format(Date - 1, "ddmmmmyyyy") & ".xls"
    End Sub


    Do not add the "\" after "FC Daily report". Also mmmm would give u the long month as "November" use mm

    it should be

    FileCopy "C:\nbutane\rsview\report\FC Daily Report.xls", "C:\nbutane\rsview\report\FC Daily Report" & Format(Date - 1, "ddmmyyyy") & ".xls"
    End Sub

    this would give u the taget file as FC Daily Report08112004.xls

    >Target (new filename) : FC Daily Report.xls 07112004.xls
    For this

    FileCopy "C:\nbutane\rsview\report\FC Daily Report.xls", "C:\nbutane\rsview\report\FC Daily Report.xls" & Format(Date - 1, "ddmmyyyy") & ".xls"
    End Sub


    Expert Comment

    Not really part of your question but you may find formatting the date as yyyymmdd will help you when it comes to sorting the list of files alphabeticallu, they will appear in date order.

    Author Comment


    Thx for ur code, you are realy good :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    Adobe Customization Wizard XI issues 26 133
    TXT to PDF help needed 26 75
    scoresAverage challenge 8 58
    How to run Invisible a .bat file? 3 35
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now