Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Protect Excel sheets with Password Using VBA

Is there a way to prompt for a password that covers all sheets when using VBA
to protect multiple sheets in a workbook?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Protect Excel sheets with Password Using VBA

This'll protect all the unprotected worksheets with the same password:

Option Explicit
Sub testme01()
Dim myPwd As String
Dim wks As Worksheet

myPwd = InputBox(prompt:="what's the password, kenny?")

If Trim(myPwd) = "" Then
Exit Sub
End If

For Each wks In ThisWorkbook.Worksheets
If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then
'already protected
Else
wks.Protect Password:=myPwd
End If
Next wks

End Sub

Iain wrote:

Is there a way to prompt for a password that covers all sheets when using VBA
to protect multiple sheets in a workbook?


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Protect Excel sheets with Password Using VBA

Thanks Dave - really appreciate the help.

"Dave Peterson" wrote:

This'll protect all the unprotected worksheets with the same password:

Option Explicit
Sub testme01()
Dim myPwd As String
Dim wks As Worksheet

myPwd = InputBox(prompt:="what's the password, kenny?")

If Trim(myPwd) = "" Then
Exit Sub
End If

For Each wks In ThisWorkbook.Worksheets
If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then
'already protected
Else
wks.Protect Password:=myPwd
End If
Next wks

End Sub

Iain wrote:

Is there a way to prompt for a password that covers all sheets when using VBA
to protect multiple sheets in a workbook?


--

Dave Peterson


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
password protect the button in Excel? cfman Excel Discussion (Misc queries) 3 March 2nd 07 09:06 PM
OT I would want protect my sheets of excel from a "password recovery" software... How? -= Luca =- Excel Worksheet Functions 3 May 31st 06 10:11 AM
password protect sheets rufusf Excel Worksheet Functions 2 March 7th 06 09:00 AM
Excel password but cant hide the sheets before entering password cakonopka[_3_] Excel Programming 1 January 30th 04 06:28 PM


All times are GMT +1. The time now is 04:43 PM.

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"