Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Determine if the protected view options are active within the document

$
0
0

At the time of opening a document, it indicates to view it I must enable editing of the protected view.

I want at the time it is detected, to close the document until deleting that configuration of Excel.

enter image description here

Is there any small VBA function that does this procedure?

error 91 occurred at variable object runtime with block not set

If Application.ProtectedViewWindows.Count > 0 Then
    ActiveWorkbook.Close savechanges:=False
    Application.Quit
Else
End If

The entire ActiveWorbook code

Private Sub Workbook_Open()

    Dim hoja As Worksheet

    For Each hoja In ThisWorkbook.Worksheets
        hoja.Visible = xlSheetVisible
    Next hoja

    If Application.ProtectedViewWindows.Count > 0 Then
        ActiveWorkbook.Close savechanges:=False
        Application.Quit
    Else
    End If

    If Not VBATrusted() Then
        Application.Visible = False
        MsgBox "Aviso. Ya no puedes usar este archivo. Comunícate con el desarrollador Arq. Luis Eduardo Ramírez Aguayo entremuros.masterplan@hotmail.com Cel. +(52) 415.151.102"
        ActiveWorkbook.Close savechanges:=False
        Application.Quit
    End If

    Sheets("Hoja1").Visible = xlVeryHidden

    '----------------------------------------------------------------'

    Application.Visible = False

    UserForm1.Show

End Sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Dim hoja As Worksheet

    Sheets("Hoja1").Visible = xlSheetVisible

    For Each hoja In ThisWorkbook.Worksheets
        If hoja.Name <> "Hoja1" Then
            hoja.Visible = xlSheetVeryHidden
        End If
    Next hoja

    '----------------------------------------------------------------'

    Sheets("HojaEscondida").Range("A4") = "admin"
    Sheets("HojaEscondida").Range("A4") = "admin"

    Application.DisplayAlerts = False

End Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If SaveAsUI Then
        MsgBox "NO SE PUEDE GUARDAR COMO."& Chr(10) _
          & "Guarde el original, usando el icono guardar,"& Chr(10) _
          & "o simplemente use la x de cerrar, y se guardará"& Chr(10) _
          & "automáticamente en el lugar correcto", vbCritical
        Cancel = True
    End If

End Sub


Function VBATrusted() As Boolean
    On Error Resume Next
    VBATrusted = (Application.VBE.VBProjects.Count) > 0
End Function

Viewing all articles
Browse latest Browse all 88835


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>