INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!

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

Jobs

Jobs from Indeed

VB Code to change filename while being copied

VB Code to change filename while being copied

(OP)
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 :):)

'''''''''''''''''''''''''''''''''''''''''''''''''
'Code
'''''''''''''''''''''''''''''''''''''''''''''''''

'VARIABLES


bPath = "E:\DRIVERS\Groep 2\" 'DESTINATION PATH

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")




'SOURCE PATH

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


'SEARCH THE FILES AND COPY TO DESTINATION

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


Next

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!

Resources

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