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

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

Copy file and rename it using VB

Hi,

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.
   
0
ckchew666
Asked:
ckchew666
1 Solution
 
vippxCommented:

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

</quote>
 

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
 use

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



0
 
ALL41_EggyCommented:
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.
0
 
ckchew666Author Commented:
Vippx,

Thx for ur code, you are realy good :)
0

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