Remap certain keys on the keyboard with Word Textbox and VBA

Posted on 2011-10-20
Last Modified: 2012-05-12
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).

Question by:JohnRobinAllen
    LVL 76

    Accepted Solution

    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


    Author Closing Comment

    This is exactly the solution I needed. I am puzzled at why I could not think of it earlier.
         As always, thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
    Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
    This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
    Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now