Форматировать столбцы И включить выделение на защищенных листах - PullRequest
0 голосов
/ 12 февраля 2019

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

Теперь я также хочу отформатировать столбцы (и / или ячейки) в этих защищенных листах.Возможно ли это?

С уважением, Рикко

    Private Sub Workbook_Open()
 For Each Sheet In Worksheets
 Sheet.Unprotect Password:="riccowendy"
 Sheet.EnableOutlining = True
 Sheet.Protect Password:="riccowendy", UserInterfaceOnly:=True
 Next
 End Sub

Ответы [ 2 ]

0 голосов
/ 12 февраля 2019

Google "vba excel изменить формат на защищенных листах" помог в этом: docs.microsoft.com ... allowformattingcells

Sub ProtectionOptions()

    ActiveSheet.Unprotect Password:="riccowendy"

    'Allow cells to be formatted on a protected worksheet.
    If ActiveSheet.Protection.AllowFormattingCells = False Then
        ActiveSheet.Protect AllowFormattingCells:=True
    End If
    ActiveSheet.Protect Password:="riccowendy", UserInterfaceOnly:=True

 MsgBox "Cells can be formatted on this protected worksheet."

End Sub
0 голосов
/ 12 февраля 2019

Попробуйте следующие подпункты.

Sub DoOutline()
 For Each sht In Worksheets
    sht.Unprotect Password:="riccowendy"
    sht.Cells.Borders(xlDiagonalDown).LineStyle = xlNone
    sht.Cells.Borders(xlDiagonalUp).LineStyle = xlNone

    With sht.Cells.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With sht.Cells.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With sht.Cells.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With sht.Cells.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With sht.Cells.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With sht.Cells.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlThin
    End With

    sht.Protect Password:="riccowendy", UserInterfaceOnly:=True
 Next
End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...