Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


VB Code to change filename while being copied

VB Code to change filename while being copied

VB Code to change filename while being copied

Hello i am new to this forum and i need some help :)

I have this code that search for a filename by name and modified Date,
It will copy the file to a new path and that works.
But while its being copied i want to rename it.

Who can help me :):)




aBeginWith = "holdings_" 'FILE BEGINS WITH

aDate = InputBox("Date", "DATE", Date) 'FILES CREATED AFTER THIS DATE

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")


Set aPath = fso.GetFolder("E:\DRIVERS\Groep 1\") 'SOURCE PATH


For Each file In aPath.Files
If RIGHT(file.Name, 4) = ".txt" and Left(file.Name, Len(aBeginWith)) = aBeginWith and DateDiff("d", File.DateLastModified, aDate) = 0 then

file.Copy bPath & file.name

'objFSO.MoveFile "E:\DRIVERS\Groep 2\holdings_********.txt" , "E:\DRIVERS\Groep 2\test.txt"

End If


RE: VB Code to change filename while being copied

You have it, just in the file.Copy command, replace "file.name" with the new filename you want.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close