+ Reply to Thread
Results 1 to 5 of 5

protect/unprotect all sheets

Hybrid View

  1. #1
    roos
    Guest

    protect/unprotect all sheets

    I use the following code to protect/unprotect all sheets in a excel file:

    Private Sub CommandButton1_Click()
    Dim wSheet As Worksheet
    For Each wSheet In Worksheets
    If wSheet.ProtectContents = True Then
    wSheet.Unprotect Password:=TextBox1.Text
    Else
    wSheet.Protect Password:=TextBox1.Text
    End If
    Next wSheet
    Unload Me
    End Sub

    It works well, but I would like that when I protect the sheets it will ask
    twice for the password. Like excel ask normally when you protect sheet for
    sheet.(tools, protection, protect sheet)
    Who knows the code for this.

  2. #2
    filo666
    Guest

    RE: protect/unprotect all sheets

    easy, in this line:
    Else
    wSheet.Protect Password:=TextBox1.Text
    End If

    you could add an userform (a new one) that asks the password again, and if
    that password is different from textbox1.text then an error msgbox appears
    HTH
    "roos" wrote:

    > I use the following code to protect/unprotect all sheets in a excel file:
    >
    > Private Sub CommandButton1_Click()
    > Dim wSheet As Worksheet
    > For Each wSheet In Worksheets
    > If wSheet.ProtectContents = True Then
    > wSheet.Unprotect Password:=TextBox1.Text
    > Else
    > wSheet.Protect Password:=TextBox1.Text
    > End If
    > Next wSheet
    > Unload Me
    > End Sub
    >
    > It works well, but I would like that when I protect the sheets it will ask
    > twice for the password. Like excel ask normally when you protect sheet for
    > sheet.(tools, protection, protect sheet)
    > Who knows the code for this.


  3. #3
    roos
    Guest

    RE: protect/unprotect all sheets

    Ok, and the code to do this?
    roos

    "filo666" wrote:

    > easy, in this line:
    > Else
    > wSheet.Protect Password:=TextBox1.Text
    > End If
    >
    > you could add an userform (a new one) that asks the password again, and if
    > that password is different from textbox1.text then an error msgbox appears
    > HTH
    > "roos" wrote:
    >
    > > I use the following code to protect/unprotect all sheets in a excel file:
    > >
    > > Private Sub CommandButton1_Click()
    > > Dim wSheet As Worksheet
    > > For Each wSheet In Worksheets
    > > If wSheet.ProtectContents = True Then
    > > wSheet.Unprotect Password:=TextBox1.Text
    > > Else
    > > wSheet.Protect Password:=TextBox1.Text
    > > End If
    > > Next wSheet
    > > Unload Me
    > > End Sub
    > >
    > > It works well, but I would like that when I protect the sheets it will ask
    > > twice for the password. Like excel ask normally when you protect sheet for
    > > sheet.(tools, protection, protect sheet)
    > > Who knows the code for this.


  4. #4
    filo666
    Guest

    RE: protect/unprotect all sheets

    still there????

    "filo666" wrote:

    > easy, in this line:
    > Else
    > wSheet.Protect Password:=TextBox1.Text
    > End If
    >
    > you could add an userform (a new one) that asks the password again, and if
    > that password is different from textbox1.text then an error msgbox appears
    > HTH
    > "roos" wrote:
    >
    > > I use the following code to protect/unprotect all sheets in a excel file:
    > >
    > > Private Sub CommandButton1_Click()
    > > Dim wSheet As Worksheet
    > > For Each wSheet In Worksheets
    > > If wSheet.ProtectContents = True Then
    > > wSheet.Unprotect Password:=TextBox1.Text
    > > Else
    > > wSheet.Protect Password:=TextBox1.Text
    > > End If
    > > Next wSheet
    > > Unload Me
    > > End Sub
    > >
    > > It works well, but I would like that when I protect the sheets it will ask
    > > twice for the password. Like excel ask normally when you protect sheet for
    > > sheet.(tools, protection, protect sheet)
    > > Who knows the code for this.


  5. #5
    roos
    Guest

    RE: protect/unprotect all sheets

    yes

    "filo666" wrote:

    > still there????
    >
    > "filo666" wrote:
    >
    > > easy, in this line:
    > > Else
    > > wSheet.Protect Password:=TextBox1.Text
    > > End If
    > >
    > > you could add an userform (a new one) that asks the password again, and if
    > > that password is different from textbox1.text then an error msgbox appears
    > > HTH
    > > "roos" wrote:
    > >
    > > > I use the following code to protect/unprotect all sheets in a excel file:
    > > >
    > > > Private Sub CommandButton1_Click()
    > > > Dim wSheet As Worksheet
    > > > For Each wSheet In Worksheets
    > > > If wSheet.ProtectContents = True Then
    > > > wSheet.Unprotect Password:=TextBox1.Text
    > > > Else
    > > > wSheet.Protect Password:=TextBox1.Text
    > > > End If
    > > > Next wSheet
    > > > Unload Me
    > > > End Sub
    > > >
    > > > It works well, but I would like that when I protect the sheets it will ask
    > > > twice for the password. Like excel ask normally when you protect sheet for
    > > > sheet.(tools, protection, protect sheet)
    > > > Who knows the code for this.


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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