尝试禁用" EnableEvents"时遇到奇怪的错误在SheetChange事件期间。
想象单元格A1带有列表验证,选项"是","否"。
如果用户双击单元格,但随后立即决定选择"是"或"否"值我得到以下错误:
运行时错误' 50290':方法' EnableEvents'对象' _Application' 失败
它很好用。只有当用户执行此操作时才会出现此错误(通常不会,但用户会执行他们的操作)。
错误保护不起作用,因为它也有EnableEvents调用你,因为我必须确保之后重新启用事件。我尝试添加' On Error Remove Next'在错误处理程序之后,但是没有工作
以下是主要代码:已编辑
类模块名为' AppObject'
Private WithEvents App As Application
Private Sub Class_Initialize()
Set App = Application
End Sub
Private Sub App_SheetChange(ByVal Sh As Object, ByVal Source As Range)
On Error GoTo ExitProcedure
App.EnableEvents = False
Call RunMySheetChangeProcedure
ExitProcedure:
App.EnableEvents = True
End Sub
标准模块名为' ModuleAppIni'
Public MyAppObject As AppObject
Sub Auto_Open()
Set MyAppObject = New AppObject
End Sub
Sub DestroyMe()
Set MyAppObject = Nothing
End Sub
答案 0 :(得分:0)
try .IgnoreBlank = False
With Range("A1").Validation
'other parameters
.IgnoreBlank = False
End With