Skip to main content
 首页 » 编程设计

c#之从 Excel 数据验证中删除帮助按钮

2024年02月20日15cloudgamer

我想从数据验证中删除帮助按钮。 在 excel 2003 数据验证中,此按钮不存在,但现在我想从 excel 2007 数据验证错误中删除此按钮。 请不要问为什么要删除帮助按钮。

我的项目类型是visual studio 2008的excel模板。

编辑

除了Worksheet_Change,还有其他方法可以完成这个事情吗?我认为这可能会降低性能。

请您参考如下方法:

如果您使用的是内置数据验证,则无法删除“帮助”按钮。建议您简单地使用帮助按钮,因为唯一已知的解决方法是重新创建 Excel 的内置功能非常耗时。

您需要创建一个自定义消息框来监听工作表更改并检查值。这是一个 VBA 示例 basically taken from here :

Private Sub Worksheet_Change(ByVal Target As Range) 
dim msg as string 
dim Style as string 
dim Title as string 
dim Response as long 
'Update Cells to be the actuall range you want to validate 
If Intersect(Target, Cells(1, 2)) Then 
    If Cells(1, 2).Value <> "whatever" Then 
        msg = "Value must be LT 1" 
        Style = vbRetryCancel + vbCritical 
        Title = "Mt Error" 
        Response = MsgBox(msg, Style, Title) 
    End If 
End If 
End Sub