+ Reply to Thread
Results 1 to 8 of 8

Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

  1. #1
    Registered User
    Join Date
    01-17-2023
    Location
    Hamburg
    MS-Off Ver
    365
    Posts
    11

    Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    Hi everyone,

    I have a macro that is hiding/showing certain rows, which is activated by a Toggle Button.
    However, the sheet on which this is set is protected.

    My problem is the following:

    When clicking the button, Excel will show the "sheet is protected"-dialogue, you would also get when trying to manually enter data in a protected sheet, even though I use Sheet.Unprotect in the macro before anything is changed on the sheet.
    Putting the Sheet.Unprotect as the first line in the Button_Click Event or using Application.DisplayAlerts also doesn't help.
    Funnily enough, the macro still works. The sheet gets unprotected, the rows are hidden and the sheet is protected again, but as I said the dialogue always shows.
    I don't really mind that, but since others are using the file and they don't know that everything is fine, when the warning shows, I would like to fix this.

    Currently my code looks like this:

    Please Login or Register  to view this content.
    The sheet is unprotected in the called Sub before anything is changed on the sheet. But as mentioned, putting the unprotect line first in the Click event does not help either.

    I would be happy to hear you guys' thought on this

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,023

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    Could you attach a desensitised copy of the file so we can see it in context? I suspect there is another piece of code being called prior to unlocking the sheet.

    BSB

  3. #3
    Registered User
    Join Date
    01-17-2023
    Location
    Hamburg
    MS-Off Ver
    365
    Posts
    11

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    I tried to recreate the issue in a new workbook, however I did not get it to produce the same behaviour.

    However, I have no idea, what could be the difference, as the code provided is the only code in the worksheet.
    I guess it must be some other events that are triggered and registered by other workbookwide code maybe? Do you have any pointers, where I might look, maybe?

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,023

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    Quote Originally Posted by _christoph View Post
    Do you have any pointers, where I might look, maybe?
    Without seeing the file?? No.

    BSB

  5. #5
    Registered User
    Join Date
    01-17-2023
    Location
    Hamburg
    MS-Off Ver
    365
    Posts
    11

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    I guess, since the data is sample data anyway, I can post the file here.
    However, it is kind of convoluted, which was why I tried to create a smaller sample file. Also I had to delete most Sheets, to get below the 1 MB max size. So most of the macros probably won't work, in case you come across any errors while testing.
    If you want to reproduce the error you have to use the ToggleButton in the top right of the Sheet, which is shown, when opening the file.
    This will hide some of the rows from the table below.

    EDIT: Removed the sample file
    Last edited by _christoph; 02-15-2023 at 07:03 AM.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,023

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    If you look at the properties of the toggle button, it's linked to cell J6. So each time you click the button it's trying to change that cell between True and False and that's what throws up the warning.

    Either make that cell unlocked then protect the sheet, or if you don't actually need the True/False value in that cell, simply unlink it from the toggle button.

    BSB

  7. #7
    Registered User
    Join Date
    01-17-2023
    Location
    Hamburg
    MS-Off Ver
    365
    Posts
    11

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    Aaaaah, that makes so much sense. Thank you!

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,023

    Re: Toggle Button triggers sheet protection warning, despite using Unprotect in the macro

    Happy to help

    BSB

+ 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. [SOLVED] VBA code to protect/unprotect workbook in order to hide/unhide sheets with toggle button
    By brettosmith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2018, 08:01 PM
  2. Unprotect a sheet that has password protection
    By cobwebs in forum Excel General
    Replies: 1
    Last Post: 01-25-2016, 04:49 PM
  3. [SOLVED] VBA - macro button - protect then unprotect sheet
    By blackburnsexcel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2014, 10:29 AM
  4. Button to toggle worksheet protection on/off?
    By Hambone70 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2013, 05:32 PM
  5. [SOLVED] Loop Through All Worksheets With Toggle Button To Proect or Unprotect With Password
    By DDM64 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2013, 02:43 PM
  6. Toggle "Protect/Unprotect sheet" in macro
    By aljanga in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2009, 07:09 PM
  7. workbook Protection Toggle Macro
    By Just Learning in forum Excel General
    Replies: 3
    Last Post: 08-30-2005, 07:05 PM

Tags for this Thread

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