Consulting

Results 1 to 4 of 4

Thread: Detecting "Protected View"

  1. #1

    Detecting "Protected View"

    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.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You can not code for that unless you code in some other workbook to look for it. See http://msdn.microsoft.com/en-us/libr.../ff822367.aspx

  3. #3
    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

  4. #4
    VBAX Newbie
    Joined
    Oct 2014
    Posts
    1
    Location

    Detecting "Protected View"

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •