Closed Thread
Results 1 to 3 of 3

Excel Sheet Protection Password

Hybrid View

sajib_148 Excel Sheet Protection... 02-17-2020, 03:42 AM
Kaper Re: Excel Sheet Protection... 02-17-2020, 05:04 AM
AliGW Re: Excel Sheet Protection... 02-17-2020, 06:30 AM
  1. #1
    Registered User
    Join Date
    05-09-2013
    Location
    Bangladesh
    MS-Off Ver
    Office 365
    Posts
    32

    Excel Sheet Protection Password

    I have a Macro Enable Excel Document. I have using following code to protect the sheet. But the problem is that when i open the workbook, Dialog Box for unprotect password is appeared. After clicking cancel, it goes away. How can i get rid out of this.

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Sheets("Summery Statement").Protect Password:="****"
    Sheets("TR").Protect Password:="****"
    ActiveWorkbook.Save
    End Sub
    
    Private Sub Workbook_Open()
    
    If Sheets("Summery Statement").Unprotect = True Then
       Sheets("Summery Statement").Protect Password:="****"
          
    If Sheets("TR").Unprotect = True Then
       Sheets("TR").Protect Password:="****"
    
    If Err.Number <> 0 Then
        MsgBox "The Password Provided is incorrect"
        Exit Sub
    End If
    On Error GoTo 0
    End If
    End If
    End Sub

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,901

    Re: Excel Sheet Protection Password

    You are trying to unprotect it, so the dialog pops-up.
    Try reading property:
    .ProtectContents

    Private Sub Workbook_Open()
    
    If Sheets("Summery Statement").ProtectContents = False Then
       Sheets("Summery Statement").Protect Password:="****"
    '...
    PS. Check the rest of the code too, because it seems that you set error skipping in one procedure and test an error in another (when error handling will be in default state - like Goto 0)
    Best Regards,

    Kaper

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2510 (Windows 11 Home 24H2 64-bit)
    Posts
    92,853

    Re: Excel Sheet Protection Password

    Administrative Note:

    Unfortunately, this is a duplicate thread, and you are allowed only ONE thread per issue here.

    Please see Forum Rule #5 about thread duplication.

    I am closing this thread, but you may continue here in the original thread: https://www.excelforum.com/excel-pro...ork-sheet.html
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Volunteer organiser & photographer with the Sutton Hoo Ship's Company: https://saxonship.org/
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Password Protection of Sheet via VBA
    By G.Bregvadze in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2017, 11:09 AM
  2. Replies: 13
    Last Post: 04-05-2017, 10:20 AM
  3. Unprotect a sheet that has password protection
    By cobwebs in forum Excel General
    Replies: 1
    Last Post: 01-25-2016, 04:49 PM
  4. Password sheet protection issue
    By Bjordion in forum Excel General
    Replies: 1
    Last Post: 09-13-2012, 12:19 PM
  5. password protection-is there anyway to put a password on running a macro in excel?
    By Solarissf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2008, 10:06 AM
  6. Removing password protection on a sheet
    By Otto.tsl in forum Excel General
    Replies: 2
    Last Post: 11-02-2005, 04:07 PM
  7. [SOLVED] Password protection of Excel Sheet linked to Bloomberg Data
    By Rohit in forum Excel General
    Replies: 0
    Last Post: 06-28-2005, 06:05 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