Determine if worksheet is password protected

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Is it possible to have a function that tells me whether a particular worksheet is password protected in a workbook before opening the workbook?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
No, not really, you could check using VBA at the workbook_open event, but I think that's about it !
 
Upvote 0
No, not really, you could check using VBA at the workbook_open event, but I think that's about it !
Ok in that case can I open the workbook using vba and then determine which worksheets are password protected and then close the workbook again using vba code?
 
Upvote 0
Maybe this way
VBA Code:
Sub Workbook_Open()
    Dim sh As String, ws As Worksheet
    For Each ws In Worksheets
    If ws.ProtectContents = True Then
        sh = sh & " " & ws.Name
        End If
    Next ws
    MsgBox "The Following Sheets are Protected !!" & sh
ActiveWorkbook.Close savechanges:=False
End Sub
 
Upvote 0
Solution
Maybe this way
VBA Code:
Sub Workbook_Open()
    Dim sh As String, ws As Worksheet
    For Each ws In Worksheets
    If ws.ProtectContents = True Then
        sh = sh & " " & ws.Name
        End If
    Next ws
    MsgBox "The Following Sheets are Protected !!" & sh
ActiveWorkbook.Close savechanges:=False
End Sub
Many thanks.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top