PDA

View Full Version : [SOLVED] Detecting "Protected View"



llldebaserll
01-17-2014, 09:27 AM
Is there a way to detect if a Workbook has been opened in "Protected View?"

I've built a tool that allows someone to edit various templates downloaded from my companies intranet. Sometimes these templates open "Protected View" due to the security/trust settings of varying computers.

If I could figure out how to detect if a workbook has been opened in this state, I could then tell the user to click the yellow button to make it editable.
But I'm having trouble with this. Excel doesn't seem to even acknowledge the existence of a workbook in "Protected View."

The Image Below:
Book1 (just a blank workbook I'm testing code in)
027_001 US_GT... (One of the workbooks that has been opened in "Protected View"
VBA Project Window (Book1 is the only shown workbook. 027_001... doesn't even appear!)

Any insight would be GREATLY appreciated.
11109

Kenneth Hobs
01-17-2014, 09:44 AM
You can not code for that unless you code in some other workbook to look for it. See http://msdn.microsoft.com/en-us/library/office/ff822367.aspx

llldebaserll
01-17-2014, 10:03 AM
Thanks Kenneth!

I don't know why that page didn't pop up in my Google searches but my problem is solved!

If anyone else ever needs to do this, here a simple way to detect if any open workbooks are in Protected View.

Sub ProtectionCheck()
If Application.ProtectedViewWindows.Count > 0 Then
MsgBox ("Please unprotect Workbooks")
End If
End Sub

Moonglum
10-30-2014, 09:36 AM
The ProtectedViewWindows Object was added in 2010, so to support earlier versions you will have to indirectly invoke the object.
Something like :


Public Property Get IsProtectedView() As Boolean
Dim Pvw As Object

On Error GoTo err_handler
Set Pvw = CallByName(Application, "ProtectedViewWindows", VbGet)
If Not Pvw Is Nothing Then
IsProtectedView = Pvw.Count > 0
End If

err_handler:
Set Pvw = Nothing
End Property