View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Joey[_4_] Joey[_4_] is offline
external usenet poster
 
Posts: 2
Default Double prompting of an over-write confirmation when saving a fileof the same name

Hello,

I have a class module which modifies the workbookBeforeSave event so
that it can execute a customized SaveAs dialogbox instead of the
standard one; however, when I click 'Save' with an existing filename it
prompts me once with the usual over-write message box and then when I
click 'Yes' it prompts me with another message box asking me the same
thing except the full path is displayed in this message box. I've tried
isolating the two over-write prompts using MsgBoxes (I was unable to set
breakpoints within the events themselves) but to no avail. The
workbookBeforeSave event is executed only once to execute my modified
SaveAs (FileSaveAs) subroutine. When I execute the SaveAs method from
within my modified SaveAs (FileSaveAs) subroutine I disable events
immediately preceding the SaveAs method and then I immediately re-enable
events after as such:

Application.EnableEvents = False
ActiveWorkbook.SaveAs sFilename
Application.EnableEvents = True

The WorkbookBeforeSave event does not fire again and MsgBoxes confirm
this yet I still get double prompting. Why would this double prompting
occur and how do I eliminate it? The WorkbookBeforeSave code is as follows:

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI
As Boolean, Cancel As Boolean)

On Error GoTo BeforeSaveError
If SaveAsUI Then 'its going to show the SaveAsUI which means user
'clicked "save as" or the file has never been 'saved
Call FileSaveAs
Else
If Not Wb.Saved Then
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
End If
End If
Cancel = True
Wb.Saved = True
Exit Sub
BeforeSaveError:
Application.EnableEvents = True
MsgBox "Error # " & Err.Number & " " & Err.Description, vbCritical,
"Cannot Save File"

End Sub

Your assistance is very much appreciated.
Thanks,
Joey.