SamarthSalunkhe
Board Regular
- Joined
- Jun 14, 2021
- Messages
- 103
- Office Version
- 2016
- Platform
- Windows
Hello Everyone,
I'm using the below code to prevent special characters in the Text box, but it doesn't work if I Paste characters directly to the text box, I guess it is happening because I am using KeyPress.
can someone help me to prevent it from copy-paste also?
I'm using the below code to prevent special characters in the Text box, but it doesn't work if I Paste characters directly to the text box, I guess it is happening because I am using KeyPress.
VBA Code:
Private Sub txtName_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("A") To Asc("Z")
Case Asc("a") To Asc("z")
Case Asc(" ") To Asc(" ")
Case Else
KeyAscii = 0
MsgBox "Special Character is not allowed in this tab", vbExclamation, "Special Character Found"
End Select
End Sub
can someone help me to prevent it from copy-paste also?