LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
dq dq is offline
external usenet poster
 
Posts: 46
Default Workbook_BeforeSave not behaving as expected

Hi,

To protect some highly confidential data in a workbook I want to make
sure this data is always hidden and the worksheet protected before
saving so it is never visible in the saved version. So I wrote the
following code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, ByRef
Cancel As Boolean)
' Check if the offending lines are visible. If not exit
If (shWork.Range("rCost").EntireRow.Hidden) Then Exit Sub

Application.ScreenUpdating = False
Application.EnableEvents = False

Call HideCosts ' Hide the offending lines
Call Me.Save ' Save the workbook
Call ShowCosts(True) ' Show the lines again
Me.Saved = True ' Showing the lines made the workbook
'unsaved' again

Application.EnableEvents = True
Application.ScreenUpdating = True
Cancel = True ' We already saved the workbook
End Sub

When I save the workbook using the 'Save' command (menu, toolbar,
programmatically) it works fine. The rows are hidden and the book is
protected. But if I want to close the workbook when it is not yet
saved, I get into a loop. Excel asks me if I want to save, I say yes
and the book is saved. Then it asks me again and again. When I say no
it simply closes but it will be very confusing to the people who'll be
using this workbook.

Has anybody an idea why I get in this loop. When the function exits,
the property 'Saved' is true, so I don't see why Excel keeps asking if
I want to save.
P.S. There is nothing in the Befor_Close event that changes anything
in the workbook.

Thanks in advance.

DQ

 
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
Workbook_BeforeSave question Frederick Chow Excel Programming 0 March 21st 06 07:24 PM
Workbook_BeforeSave() bmm Excel Programming 3 August 16th 04 03:37 PM
Workbook_Beforesave getting breached Hari[_3_] Excel Programming 2 June 11th 04 10:57 PM
Workbook_BeforeSave Bill Oertell Excel Programming 5 December 21st 03 07:33 PM
Workbook_BeforeSave() in xla Bent Kjeldsen Excel Programming 6 September 24th 03 01:49 PM


All times are GMT +1. The time now is 02:51 PM.

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"