Problemas con tu macro en excel

Me colaboras con algo de tu código

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Por.Dante Amor
    For Each h In Sheets
        h.Unprotect "abc"
        h.Cells.Locked = False
        h.UsedRange.SpecialCells(xlCellTypeConstants, 23).Locked = True
        h.Protect "abc", DrawingObjects:=False, Contents:=True, Scenarios:=False, _
            AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, _
            AllowInsertingColumns:=True, AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
            AllowDeletingColumns:=True, AllowDeletingRows:=True, AllowSorting:=True, _
            AllowFiltering:=True, AllowUsingPivotTables:=True
    Next
    ThisWorkbook.Save
End Sub

el código me funciona muy bien pero estoy intento hacer lo siguiente:

Obligar a los usuarios para que habiliten las macros, se he estado haciendo con una página de inicio y ocultando las otras hojas pero el código bloquea todo el libro.

h.UsedRange.SpecialCells(xlCellTypeConstants, 23).Locked = True

este el codigo que utilizo para ocultar las hojas 

Dim hoja As Worksheet
Sheets("inicio").Visible = xlSheetVisible
For Each hoja In ThisWorkbook.Worksheets
If hoja.Name <> "inicio" Then
hoja.Visible = xlSheetVeryHidden
End If
Next hoja
ActiveWorkbook.Save

End Sub

Private Sub Workbook_Open()
Dim hoja As Worksheet

For Each hoja In ThisWorkbook.Worksheets
hoja.Visible = xlSheetVisible
Next hoja
Sheets("inicio").Visible = xlSheetVeryHidden
End Sub

1 Respuesta

Respuesta
2

Prueba así:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Por.Dante Amor
    For Each h In Sheets
        If h.Name <> "inicio" Then
            h.Unprotect "abc"
            h.Cells.Locked = False
            h.UsedRange.SpecialCells(xlCellTypeConstants, 23).Locked = True
            h.Protect "abc", DrawingObjects:=False, Contents:=True, Scenarios:=False, _
                AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, _
                AllowInsertingColumns:=True, AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
                AllowDeletingColumns:=True, AllowDeletingRows:=True, AllowSorting:=True, _
                AllowFiltering:=True, AllowUsingPivotTables:=True
        End If
    Next
    ThisWorkbook.Save
End Sub

Avísame cualquier duda.. No olvides valorar la respuesta. Sal u dos

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas