×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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

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

Jobs

Saving the same file with diffrent name in one folder

Saving the same file with diffrent name in one folder

Saving the same file with diffrent name in one folder

(OP)
I've got some macro which generates text file and saves it in folder.The point is to create some macro which allows save the same file with diffrent name in the same directory.Its mean add to old name number one bigger and save it in the same path.Just like in windows.When you are creating copy of file in the same path,the copy has got old name with added number in brackets.
I will be grateful for any help.

RE: Saving the same file with diffrent name in one folder

Try something like this:

One text file saves the master name - such as MYFILE100

Next time you need to save a new file use some string manipulation to make the new file name as MYFILE101

Or better yet just save the last used number.  Increment it by one evertime you need a new name...and "add" it to MYFILE
using strings.

RE: Saving the same file with diffrent name in one folder

Try this:

CODE

Private Sub CommandButton1_Click()
'set up your path
myPath = "c:\"
'and your base filename
'getfirst file with that basename
x = Dir(myPath & "\myFile*.txt")
'then loop until the last one of the set
Do While Len(x) > 0
Lastfile = x
x = Dir
Loop
'now get the last number
Newname = Mid(Lastfile, 7)
' and increment it
Newnum = Val(Newname) + 1
' construct full paths for source and destination
Lastfile = myPath & Lastfile
NewFile = myPath & "myFile" & Format(Newnum, "000") & ".txt"
' and copy
FileCopy Lastfile, NewFile
End Sub

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376: Eng-Tips.com Forum Policies before posting
Steam Engine enthusiasts
Steam Engine Prints

RE: Saving the same file with diffrent name in one folder

(OP)
I've resolved it in other way.But many thanks for your help.

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 Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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


Resources