View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Roger Govier[_3_] Roger Govier[_3_] is offline
external usenet poster
 
Posts: 2,480
Default How to prevent overwriting of file ?

Hi

The following code entered into the ThisWorkbook module could be used.

You will need to amend to suit your circumstances, and add some checks to
ensure the user doesn't add .xls to the end of the name they give etc., but
it should get you started

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim filename As String, oldname As String
oldname = ThisWorkbook.Name
Application.EnableEvents = False
entername:
filename = ""
filename = InputBox ("Enter a NEW Filename to save this file as")
filename = filename & ".xls"
If oldname = filename Then
MsgBox ("You have chosen the same name " & oldname & vbCr _
& " Choose something different")

GoTo entername
End If
ThisWorkbook.SaveAs filename
Application.EnableEvents = True
End Sub
--
Regards
Roger Govier

wrote in message
...
Vow.. It works..Great , thanks...
Hey, but is there any way by which I can force a SaveAs when the file
being saved has some specific name, else just save ... ?