ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel XP and WorkbookBeforeSave (https://www.excelbanter.com/excel-programming/347134-excel-xp-workbookbeforesave.html)

Dave McL.

Excel XP and WorkbookBeforeSave
 
The following code snippet works fine in Excel 2003, but XP behaviour is
different.
In Excel XP I get prompted to save the file twice.
Any ideas - TIA Dave

Private Sub m_ThisApplication_WorkbookBeforeSave(ByVal Wb As
Microsoft.Office.Interop.Excel.Workbook, ByVal SaveAsUI As Boolean, ByRef
Cancel As Boolean) Handles m_ThisApplication.WorkbookBeforeSave

If SaveAsUI Then
sBeforeSaveFilename = Wb.Name
m_ThisApplication.EnableEvents = False
m_ThisApplication.Dialogs(xlDialogSaveAs).Show()

' prevent a second save
m_ThisApplication.EnableEvents = True
Cancel = True
End If
Wb = Nothing


Patrick Molloy[_2_]

Excel XP and WorkbookBeforeSave
 
it is not the enable events method that you turn off, it's the display alerts
method that you turn off. Alternatively, set the workbooks SAVED property to
TRUE.

"Dave McL." wrote:

The following code snippet works fine in Excel 2003, but XP behaviour is
different.
In Excel XP I get prompted to save the file twice.
Any ideas - TIA Dave

Private Sub m_ThisApplication_WorkbookBeforeSave(ByVal Wb As
Microsoft.Office.Interop.Excel.Workbook, ByVal SaveAsUI As Boolean, ByRef
Cancel As Boolean) Handles m_ThisApplication.WorkbookBeforeSave

If SaveAsUI Then
sBeforeSaveFilename = Wb.Name
m_ThisApplication.EnableEvents = False
m_ThisApplication.Dialogs(xlDialogSaveAs).Show()

' prevent a second save
m_ThisApplication.EnableEvents = True
Cancel = True
End If
Wb = Nothing


Dave McL.[_2_]

Excel XP and WorkbookBeforeSave
 
By leaving EnableEvents on the event "WorkbookBeforeSave" will get fired
twice, creating the same problem.
Application.ActiveWorkbook.Saved is set to true by
"m_ThisApplication.Dialogs(xlDialogSaveAs).Show()" .
Setting display alerts to false had no effect.

Cheers
Dave

"Patrick Molloy" wrote:

it is not the enable events method that you turn off, it's the display alerts
method that you turn off. Alternatively, set the workbooks SAVED property to
TRUE.

"Dave McL." wrote:

The following code snippet works fine in Excel 2003, but XP behaviour is
different.
In Excel XP I get prompted to save the file twice.
Any ideas - TIA Dave

Private Sub m_ThisApplication_WorkbookBeforeSave(ByVal Wb As
Microsoft.Office.Interop.Excel.Workbook, ByVal SaveAsUI As Boolean, ByRef
Cancel As Boolean) Handles m_ThisApplication.WorkbookBeforeSave

If SaveAsUI Then
sBeforeSaveFilename = Wb.Name
m_ThisApplication.EnableEvents = False
m_ThisApplication.Dialogs(xlDialogSaveAs).Show()

' prevent a second save
m_ThisApplication.EnableEvents = True
Cancel = True
End If
Wb = Nothing



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com