+ Reply to Thread
Results 1 to 7 of 7

Unprotect sheets in workbook deactivate event

  1. #1
    Registered User
    Join Date
    02-26-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    5

    Unprotect sheets in workbook deactivate event

    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

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Unprotect sheets in workbook deactivate event

    Hi,

    Try placing your worksheet unprotect code into the Workbook_BeforeClose subroutine also, found in the ThisWorkbook module.

    Let me know if this helps

  3. #3
    Registered User
    Join Date
    02-26-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Unprotect sheets in workbook deactivate event

    Thanks for the response mate, but the result is the same. The unprotect code is equally ineffective in the Workbook_BeforeClose sub.

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Unprotect sheets in workbook deactivate event

    OK,

    Do you have a sample workbook that you could upload?

    Thanks

  5. #5
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Unprotect sheets in workbook deactivate event

    Or...try placing the worksheet unprotect code just before ThisWorkbook.Close is called...

  6. #6
    Registered User
    Join Date
    02-26-2013
    Location
    Melbourne
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Unprotect sheets in workbook deactivate event

    Excellent mate. I put it in another sub called just before ThisWorkbook.Close - it did the trick. Thanks very much.

  7. #7
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Unprotect sheets in workbook deactivate event

    Perfect!

    No problems. Please don't forget to mark this thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Deactivate event appears to be overriding next activate event
    By ezrizer in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-01-2013, 10:15 AM
  2. [SOLVED] Deactivate Event only on if statment
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-30-2012, 05:10 PM
  3. [SOLVED] Workbook Deactivate event problem
    By Jeremy Strom in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-24-2006, 06:10 PM
  4. Macros for Protect/Unprotect all sheets in a workbook
    By Paul Sheppard in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2005, 10:36 AM
  5. Macros for Protect/Unprotect all sheets in a workbook
    By Paul Sheppard in forum Excel General
    Replies: 2
    Last Post: 08-04-2005, 11:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1