+ Reply to Thread
Results 1 to 5 of 5

VBA code for Unprotect Sheet by button click an display messages

  1. #1
    Registered User
    Join Date
    08-23-2016
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    9

    VBA code for Unprotect Sheet by button click an display messages

    Hi there,

    checked the forum for similar situations but was not able to find something similar where I could start from...
    So:
    I have a protected workbook with a password ("pass1" for example); for locking I use a button with as simple code, the unlocking part is where I need help.
    1- When I click on the "unlock" button, the excel "enter password" box pops up and you enter the password.
    2- if it's Ok, then it displays the message "Sheet Unprotected", if the password is false it goes "Wrong password".

    The code looks like this:
    Please Login or Register  to view this content.
    The problem:
    If one clicks on the cancel or close button in the "enter pass" pop up window, then the "Sheet Unprotected" message comes up - which of course is not true.

    The idea is (but don't know to write the proper code):
    1. If you enter the right password, then display the message "Sheet Unprotected".
    2. If you enter the wrong pass, then display "Wrong password"
    3. If you either close the window or click cancel, the just close the window, no need for a pop up message.

    I would be really grateful for any suggestions.
    Last edited by RandomVBA; 08-24-2016 at 03:14 AM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA code for Unprotect Sheet by button click an display messages

    RandomVBA please review the forum rules, especially #3... about using code tags. Thanks!

    Please edit your post after that to include the code tags (highlight your code portion of your post and hit the # icon in the menu above the box where you type).

    As for solution to your problem replace

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: VBA code for Unprotect Sheet by button click an display messages

    Something like:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-23-2016
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    9

    Re: VBA code for Unprotect Sheet by button click an display messages

    Quote Originally Posted by Arkadi View Post
    RandomVBA please review the forum rules, especially #3... about using code tags. Thanks!

    Please edit your post after that to include the code tags (highlight your code portion of your post and hit the # icon in the menu above the box where you type).

    As for solution to your problem replace

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.

    I apologize for the mistake, I did edit the post and now it should be ok.

    Anyhow, thank you very much for the code. It works perfect!

    Regards.
    Last edited by RandomVBA; 08-24-2016 at 03:30 AM.

  5. #5
    Registered User
    Join Date
    08-23-2016
    Location
    Slovenia
    MS-Off Ver
    2010
    Posts
    9

    Re: VBA code for Unprotect Sheet by button click an display messages

    Quote Originally Posted by abduljaleel.mca View Post
    Something like:
    Please Login or Register  to view this content.
    Thank you for your help.
    I did try something similar (with the input box), but I don't really fancy the solution as the password, while being typed in, can be seen (instead of the usual "password black dots").

    I found the solution from Arkadi to work perfect.
    So, here is the final code:

    Please Login or Register  to view this content.

+ 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] Click a button: Check sheet, display errors?
    By rrbee in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2014, 10:14 AM
  2. Replies: 0
    Last Post: 02-28-2013, 03:11 PM
  3. I want vba code to extract details from one sheet to another by button click
    By Raj@Akhil in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2012, 05:27 AM
  4. [SOLVED] How to unprotect a sheet on click of a dropdown box
    By cappy82 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2011, 09:03 AM
  5. Unprotect sheet on click of dropdown box
    By cappy82 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2011, 07:44 AM
  6. Unprotect sheet button!??
    By Neo1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-29-2006, 10:46 AM
  7. [SOLVED] Code for opening another sheet on button click
    By pmud in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-18-2005, 06:06 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