Пароль защищает только некоторые листы в Excel VBA - PullRequest
0 голосов
/ 04 февраля 2020

Поэтому я пытался включить код для защиты всех рабочих листов в своем рабочем листе с использованием VBA с различными свойствами на листе. Я играл со следующим кодом, но по какой-то причине он защищает только некоторые листы паролем, а не другими. Пожалуйста, помогите.

Sub ProtegerTodo()



Sheets("Sheet1").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Sheet1").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Consecutivo de Cirugías").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Consecutivo de Cirugías").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Nueva CX").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=True, _
    AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
'Sheets("Nueva CX").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
Sheets("Nueva CX").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Catalogo").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Catalogo").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Procedimientos").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Procedimientos").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Inventario").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=False, _
    AllowFormattingColumns:=False, _
    AllowFormattingRows:=False, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Inventario").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

Sheets("Ingreso de material").Protect Password:="Password", _
    UserInterfaceOnly:=True, _
    DrawingObjects:=False, _
    Contents:=True, _
    Scenarios:=False, _
    AllowFormattingCells:=True, _
    AllowFormattingColumns:=True, _
    AllowFormattingRows:=True, _
    AllowInsertingColumns:=False, _
    AllowInsertingRows:=False, _
    AllowInsertingHyperlinks:=False, _
    AllowDeletingColumns:=False, _
    AllowDeletingRows:=False, _
    AllowSorting:=False, _
    AllowFiltering:=True, _
    AllowUsingPivotTables:=False

'Allowing selection of locked or unlocked cells
Sheets("Ingreso de material").EnableSelection = xlNoRestrictions

'Allowing selection of unlocked cells only
'Sheets("Sheet1").EnableSelection = xlUnlockedCells

'Do not allow selection of any cells
'Sheets("Sheet1").EnableSelection = xlNoSelection

End Sub

Примечание: я знаю, что это не очень эффективно, но это должно сработать.

Заранее спасибо.

1 Ответ

0 голосов
/ 04 февраля 2020

Только что попробовал ваш код, и он работал на каждом листе. Попробуйте удалять по одному листу за раз и удалить код защиты, чтобы найти точный лист, с которого начинается проблема.

Затем сохраните только этот лист и попытайтесь защитить его с помощью кода. Если произойдет сбой, защитите его, щелкнув правой кнопкой мыши по имени листа, и вы получите сообщение о проблеме в пользовательском интерфейсе - иногда код не сообщает об ошибках.

Дайте мне знать, если это поможет.

...