Remap certain keys on the keyboard with Word Textbox and VBA

I have a textbox in a Word document, and I want to remap certain keys so that they produce French accented characters instead of what they would normally produce.

     One example: If a user types "[", I want the textbox to show "é".

     I can capture the key pressed with the KeyPress Sub KeyAscii value. What I cannot do is change that KeyAscii value to anything over 128 (or maybe it is 127), yet if I want that character to appear (Chr(130), I guess I cannot use the KeyPress event.

     Any suggestions?  This is my third or fourth question to EE in two or three days, so I guess I am abusing your kindness is saving me weeks of work, but for the moment I have to ask this question. I presume that someone is going to save me a week or two of work by giving me an answer (if one exists).

     Thanks!
     JRA
JohnRobinAllenRetired professor of FrenchAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
What's the problem JRA?

If you are using an ActiveX control, then this works for me:
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    Select Case Chr$(KeyAscii)
        Case "["
            KeyAscii = Asc("é")
    End Select
End Sub

Open in new window

0
 
JohnRobinAllenRetired professor of FrenchAuthor Commented:
This is exactly the solution I needed. I am puzzled at why I could not think of it earlier.
     As always, thanks!
     JRA
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.