Buttons flicker despite Application.ScreenUpdating

2019-08-17 15:39发布

I have a class that I call at the beginning of some subs:

Private bSattOmdomenProtected As Boolean
Private bSkapaOmdomeslistorProtected As Boolean


Private Sub Class_Initialize()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Cursor = xlWait


    'Protection
    bSattOmdomenProtected = wSattOmdomen.ProtectContents
    bSkapaOmdomeslistorProtected = wSkapaOmdomeslistor.ProtectContents
    wSattOmdomen.Unprotect
    wSkapaOmdomeslistor.Unprotect
    'End protection

End Sub

Private Sub Class_Terminate()


    'Protection
    If bSattOmdomenProtected Then
        wSattOmdomen.Protect AllowSorting:=True, AllowFiltering:=True 'AllowFormattingCells:=True , UserInterfaceOnly:=True
    End If
    If bSkapaOmdomeslistorProtected Then
        wSkapaOmdomeslistor.Protect AllowSorting:=True, AllowFiltering:=True 'AllowFormattingCells:=True,, UserInterfaceOnly:=True
    End If
    'End protection

    Application.Cursor = xlDefault
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub

Example of how I call the class:

Sub Example()
    Dim general As New cGeneralLines
    Set general = New cGeneralLines

    'Code
End Sub

I find this to work well for setting application states. But since I added the code labeled Protection in the class, all buttons in my worksheets flicker, even though I have set Application.ScreenUpdating = False.

The specific line that causes the flicker seems to be when I try to change the protection settings of another sheet than the active one.

Why is this? How can I have the functionality of the sheet protection code but avoid getting flickering buttons?

0条回答
登录 后发表回答