我有一个 Excel 表,用户将在每个单元格中输入元数据。我需要做的是编写一个只允许字母数字字符和逗号的宏。
我为测试目的编写了一个不允许特殊字符的宏。但是在我在单元格中输入一个有效字符后,它允许我不允许使用的字符。我不知道如何纠正它。
我的代码:
Private Sub WorkBook_Open()
MsgBox "Running the Disable_Keys() Macro"
Call ThisWorkbook.Disable_Keys
End Sub
Sub MyMsg()
MsgBox "Press Another Key"
End Sub
Sub Disable_Keys()
Dim I As Long
Dim KeysArray As Variant
Dim Key As Variant
KeysArray = Array("@", "!", "~", "#", "$", "&", "|", "\", ":", "*", "_", "-", "=", "'", ";", "<", ">", "?", "/", "'", ":")
For Each Key In KeysArray
Application.OnKey Key, "ThisWorkbook.MyMSg"
Next Key
End Sub