Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to Unlock All Protected Worksheets

Good morning. A couple of weeks ago, someone from this forum, was very
helpful in my question on how to unprotect protected worksheets, with similar
passwords, with a macro. Below is a copy of the VB script I was given. It
worked but then I realized, the password "hi" is now visible under the macro
script. Is there a way to rewrite the code so that it will not show the
password and instead when the macro is run, one has to enter the password
before the macro can unprotect the protected worksheets?

thank you very much,
Storm

Option Explicit
sub testme()
dim myPWD as string
dim wks as worksheet
myPWD = "hi"
for each wks in activeworkbook.worksheets
wks.unprotect password:=mypwd
next wks
end sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to Unlock All Protected Worksheets

Assuming that all the worksheets have the same password, you can use code
like


Sub UnlockWorksheets()
Dim PW As String
Dim WS As Worksheet

On Error GoTo ErrHandler:
PW = Application.InputBox(prompt:="Enter Password", Type:=2)
If StrPtr(PW) = 0 Then
' user cancelled
Exit Sub
End If

For Each WS In Worksheets
WS.Unprotect Password:=PW
Next WS
Exit Sub
ErrHandler:
MsgBox "Invalid Password", vbOKOnly

End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Storm" wrote in message
...
Good morning. A couple of weeks ago, someone from this forum, was very
helpful in my question on how to unprotect protected worksheets, with
similar
passwords, with a macro. Below is a copy of the VB script I was given.
It
worked but then I realized, the password "hi" is now visible under the
macro
script. Is there a way to rewrite the code so that it will not show the
password and instead when the macro is run, one has to enter the password
before the macro can unprotect the protected worksheets?

thank you very much,
Storm

Option Explicit
sub testme()
dim myPWD as string
dim wks as worksheet
myPWD = "hi"
for each wks in activeworkbook.worksheets
wks.unprotect password:=mypwd
next wks
end sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Macro to Unlock All Protected Worksheets

On Sep 17, 8:49 am, "Chip Pearson" wrote:
Assuming that all the worksheets have the same password, you can use code
like

Sub UnlockWorksheets()
Dim PW As String
Dim WS As Worksheet

On Error GoTo ErrHandler:
PW = Application.InputBox(prompt:="Enter Password", Type:=2)
If StrPtr(PW) = 0 Then
' user cancelled
Exit Sub
End If

For Each WS In Worksheets
WS.Unprotect Password:=PW
Next WS
Exit Sub
ErrHandler:
MsgBox "Invalid Password", vbOKOnly

End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consultingwww.cpearson.com
(email on the web site)

"Storm" wrote in message

...



Good morning. A couple of weeks ago, someone from this forum, was very
helpful in my question on how to unprotect protected worksheets, with
similar
passwords, with a macro. Below is a copy of the VB script I was given.
It
worked but then I realized, the password "hi" is now visible under the
macro
script. Is there a way to rewrite the code so that it will not show the
password and instead when the macro is run, one has to enter the password
before the macro can unprotect the protected worksheets?


thank you very much,
Storm


Option Explicit
sub testme()
dim myPWD as string
dim wks as worksheet
myPWD = "hi"
for each wks in activeworkbook.worksheets
wks.unprotect password:=mypwd
next wks
end sub- Hide quoted text -


- Show quoted text -


And If we wanted to "re-lock" using the same password what would we
add?
Dennis

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to unlock and lock cells in password protected sheet Chris Excel Discussion (Misc queries) 3 February 26th 10 09:06 PM
How to Unlock Worksheets with a Macro? Storm Excel Worksheet Functions 6 September 17th 07 05:49 PM
Unlock protected VBA equiangular Excel Programming 3 February 27th 07 09:44 AM
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. Daniel Excel Worksheet Functions 1 June 24th 05 02:59 PM
How do i unlock protected worksheets? jamesbialek Excel Worksheet Functions 1 June 22nd 05 01:02 PM


All times are GMT +1. The time now is 02:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"