LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Rename rather than overwrite existing file

Hello all,
I have a workbook that saves a file with the following code:
Function DoesPathExist(myPath As String) As Boolean

Dim TestStr As String
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

TestStr = ""
On Error Resume Next
TestStr = Dir(myPath & "nul")
On Error GoTo 0

DoesPathExist = CBool(TestStr < "")

End Function

Dim myParentFolder As String
Dim myFolder As String
myParentFolder = "U:\"
Application.DisplayAlerts = False
If DoesPathExist(myParentFolder) Then
On Error Resume Next
MkDir myParentFolder & mycsj
MkDir myParentFolder & mycsj & "\Pay Reports"
MkDir myParentFolder & mycsj & "\Pay Reports" & "\" &
Range("name")
On Error GoTo 0
myFolder = myParentFolder & mycsj & "\Pay Reports" & "\" &
Range("name")
myFileName = Range("file")
myFileName = myFolder & "\" & myFileName & ".xls"
ActiveWorkbook.SaveAs Filename:= _
myFileName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "File Saved to " & myFileName
Else
myParentFolder = "C:\"
On Error Resume Next
MkDir myParentFolder & mycsj
MkDir myParentFolder & mycsj & "\Pay Reports"
MkDir myParentFolder & mycsj & "\Pay Reports" & "\" &
Range("name")
On Error GoTo 0
myFolder = myParentFolder & mycsj & "\Pay Reports" & "\" &
Range("name")
myFileName = Range("file")
myFileName = myFolder & "\" & myFileName & ".xls"
ActiveWorkbook.SaveAs Filename:= _
myFileName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
MsgBox "File Saved to " & myFileName
End If
Application.DisplayAlerts = True
End Sub

This works fine, however when I need to create a new workbook to continue
where the old one left off it simply overwrites the old one. I need it to
have the same name only add a "2" to the end of the old file name, and if
another is created then add a "3" and so on, any help is greatly appreciated.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a new file, name it and overwrite an existing name without confimation Rob[_5_] Excel Programming 2 January 14th 07 01:31 PM
accidentally click YES to overwrite an existing file mtrent Excel Discussion (Misc queries) 2 March 30th 06 07:01 PM
Overwrite existing file without prompt Tom Ogilvy Excel Programming 0 September 17th 04 01:41 PM
Overwrite existing file without prompt Mark Excel Programming 0 September 17th 04 01:21 PM
Using SaveAs Statement to overwrite existing File Peter Excel Programming 3 June 16th 04 12:27 PM


All times are GMT +1. The time now is 07:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"