Vba 尽管有应用程序,按钮仍会闪烁。ScreenUpdate=False?
我有一个类,我在一些sub的开头调用它:Vba 尽管有应用程序,按钮仍会闪烁。ScreenUpdate=False?,vba,excel,Vba,Excel,我有一个类,我在一些sub的开头调用它: Private bSattOmdomenProtected As Boolean Private bSkapaOmdomeslistorProtected As Boolean Private Sub Class_Initialize() Application.ScreenUpdating = False Application.EnableEvents = False Application.Cursor = xlWait
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
我如何调用该类的示例:
Sub Example()
Dim general As New cGeneralLines
Set general = New cGeneralLines
'Code
End Sub
我发现这对设置应用程序状态很有效。但是,自从我在类中添加了标记为Protection的代码后,我的工作表中的所有按钮都会闪烁,即使我已将Application.ScreenUpdating设置为False
导致闪烁的特定行似乎是当我尝试更改另一张图纸的保护设置而不是激活的图纸时
为什么会这样?我怎样才能既拥有纸张保护代码的功能,又避免按钮闪烁?您是否尝试过将DoEvents放在该行之前?我以前从未遇到过DoEvents。我稍后再试。我们希望用它实现什么?来自微软网站:DoEvents函数放弃宏的执行,以便操作系统可以处理其他事件。我过去曾用它来解决闪烁问题,但我对它到底在做什么不太了解。这解决了你的问题吗?没有。我后来发现闪烁发生是因为我的代码在执行过程中切换了sheed。即使在application.ScreenUpdate再次设置为true之前Excel已返回起始工作表,工作表上的按钮和其他内容也将重新绘制。我发现这就是正在发生的事情,但没有找到任何方法来阻止这种行为。