Checar si el archivo esta desprotegido
Publicado por Oscar Gabriel (35 intervenciones) el 11/02/2008 17:31:27
Hola todos,
Estoy realizando un Macro utilizando el evento BeforeSave, el cual quiero que cheque si alguna de las hojas esta desprotegida y de ser asi que pregunte al usuario si desea proteger la hoja y guardar o cancelar. El problema que tengo es que comó programo para que VBA cheque si una hoja esta desprotegida??, me he estado rompiendo la cabeza y ya busque en la ayuda de VBA y recurro a ustedes como ultimo recurso, espero que me puedan ayudar.
Este es mas o menos como esta mi macro:
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
Dim wsheet As Worksheet
For Each wsheet In Worksheets
wsheet.select
If wsheet.Unprotect = True Then '// AQUI ES DONDE NO SE QUE PONER!
a = MsgBox("La hoja " & wsheet & " esta desprotegida, desea Protegerla antes de guardar?", vbOKCancel, "Hoja desprotegida")
If a = vbCancel Then
Cancel = True
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowUsingPivotTables:=True
ActiveSheet.save
End If
Next
End Sub
Estoy realizando un Macro utilizando el evento BeforeSave, el cual quiero que cheque si alguna de las hojas esta desprotegida y de ser asi que pregunte al usuario si desea proteger la hoja y guardar o cancelar. El problema que tengo es que comó programo para que VBA cheque si una hoja esta desprotegida??, me he estado rompiendo la cabeza y ya busque en la ayuda de VBA y recurro a ustedes como ultimo recurso, espero que me puedan ayudar.
Este es mas o menos como esta mi macro:
Private Sub Workbook_BeforeSave(ByVal SaveAsUi As Boolean, Cancel As Boolean)
Dim wsheet As Worksheet
For Each wsheet In Worksheets
wsheet.select
If wsheet.Unprotect = True Then '// AQUI ES DONDE NO SE QUE PONER!
a = MsgBox("La hoja " & wsheet & " esta desprotegida, desea Protegerla antes de guardar?", vbOKCancel, "Hoja desprotegida")
If a = vbCancel Then
Cancel = True
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:= _
False, AllowFormattingCells:=True, AllowUsingPivotTables:=True
ActiveSheet.save
End If
Next
End Sub
Valora esta pregunta


0