G'day Comrades,
This is my first post. I'm using Excel 2007. The file has most cells protected as the users interact with it through dialog boxes.
I have a some code in the Workbook_Deactivate event which 1) unprotects all sheets, 2) does some formatting, 3) re-protects all sheets before closing. This works fine when I take action to close the file. However, because it is used by several people who invariably leave it open and lock out other users, I added in a sub I found called TestForUpdates which checks for updates and closes the file if it is not in active use after five minutes.
' If EditDate <= Now - TimeValue("00:05:00") Then
' If ThisWorkbook.Saved = False Then
' ThisWorkbook.Save
' End If
' ThisWorkbook.Close
' Else
' Application.OnTime Now + TimeValue("00:00:20"), "TestForUpdates"
' End If
My problem - when the Workbook_Deactivate code runs following on from the "ThisWorkbook.Close" code cited above, the worksheet.unprotect
code (see below) does not appear to work.
For Each wsheet In ThisWorkbook.Worksheets
wsheet.Unprotect Password:="3256"
Next wsheet
I would appreciate some advice on this please.
Tony
Bookmarks