简体   繁体   English

Excel运行时错误'13'

[英]Excel Run-time error '13'

I use this VBA to lookup typing word in my database. 我使用此VBA查找数据库中键入的单词。 if I type the word that is not in database, it will show disboard "Run-time error '13'"...help me dismiss it when I am typing new word 如果我键入不在数据库中的单词,它将显示disboard“运行时错误'13'” ...帮助我在键入新单词时将其关闭

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$3" Then
ActiveSheet.Hyperlinks.Add Anchor:=[C3], Address:="", SubAddress:= _
"EV!C" & Cells(3, 3)
End If
End Sub

You could always add On Error Resume Next at the top of your sub. 您总是可以On Error Resume Next顶部添加On Error Resume Next In general I am not a fan of this construct (since errors should be handled rather than ignored), but a one-statement sub is a reasonable use-case for it. 通常,我不喜欢这种构造(因为应该处理错误而不是忽略错误),但是单语句子是一个合理的用例。 If an error is encountered, the sub will have no effect, which is what you seem to want. 如果遇到错误,则该子项将无效,这似乎是您想要的。 On the other hand, you could do something like: 另一方面,您可以执行以下操作:

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo err_handler
    If Target.Address = "$B$3" Then
        ActiveSheet.Hyperlinks.Add Anchor:=[C3], Address:="", SubAddress:= _
        "EV!C" & Cells(3, 3)
    End If
    Exit Sub
err_handler:
    MsgBox "Please enter a valid word."
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM