Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving the same file with diffrent name in one folder

Status
Not open for further replies.

Cessar

Mechanical
May 9, 2007
7
0
0
FR
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.
 
Replies continue below

Recommended for you

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.
 
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 before posting
Steam Engine enthusiasts
Steam Engine Prints
 
Status
Not open for further replies.
Back
Top