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.
I will be grateful for any help.





RE: Saving the same file with diffrent name in one folder
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
CODE
'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