[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 28852
  • Last Modified:

Copy file and rename it using VB


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.
1 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

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.
ckchew666Author Commented:

Thx for ur code, you are realy good :)

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now