View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Warning Message to Prevent Overwritting

Maybe you put the code in the wrong spot--hard to tell without seeing the rest
of the code.

Or maybe you still got the overwrite message and decided to cancel so the
..SaveAs failed.

dim resp as long

.....lots of code

resp = vbyes
if dir(progname) < "" then
resp = Msgbox(Prompt:="Overwrite existing file?", buttons:=vbyesno)
end if
if resp = vbyes then
'stop the warning message
application.displayalerts = false
'now your code to save the file
application.displayalerts = true
else
'warning and get out???
end if

maperalia wrote:

Dave;
Thanks for your quick response.
I put the statement in my program eventhough I got the window message if I
want to overwrite it Excel crashs it after is doen.
Do you know waht could happened.

Thanks.
Maperalia

"Dave Peterson" wrote:

after you determine the progname:

dim resp as long

.....lots of code

resp = vbyes
if dir(progname) < "" then
resp = Msgbox(Prompt:="Overwrite existing file?", buttons:=vbyesno)
end if
if resp = vbyes then
'save the file
else
'warning and get out???
end if

(Not too much error checking in this. So watch out.)


maperalia wrote:

I have a macro which does the following:
1.- Save a file at specific path. The filename is taken from a specific cells
2.- Create a database. Find the last empty row then write the new filename.

However, I have noticed that I made a mistake and typed the same data at the
specific cells to create the filename and click the macro to save it. This
filename went at the last empty row of the database (as I expected it) but
overwrote the last filename. Therefore, I have now two filenames with the
same description in my database saved it at different time and overwritten
with the last information.

Is there is a way to write an statement before save the file to warning that
this filename already exist and ask me if I want to overwrite it?.

For your information the statement I use to save the file is the following:

€˜&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Dim Boring As String
Dim WO As String
Dim depth As String

WO = Worksheets("DEFAULTS").Range("C3")
Boring = Worksheets("DEFAULTS").Range("C5")
depth = Worksheets("DEFAULTS").Range("C6")
ClienName = Worksheets("DEFAULTS").Range("C8")

Progname = "S:\GEOTEST\shears\" & WO & "\" & Boring & " " & "@" & " " &
depth & ".xls"

€˜&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Thanks in advance.
Maperalia


--

Dave Peterson


--

Dave Peterson