Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    861
    Thanks
    0
    Thanked 10 Times in 9 Posts

    ENTER key / VBA (Word XP)

    I have a text control in a user form which I want to be multi-line (MultiLine = TRUE) , so that as the user types many characters, text will wrap within the control. I do NOT want the ENTER key to move focus to the next control in the Tab Order. But I also do not want ENTER to create a new line withint the control; everything must be in a single paragraph.

    I have tried using the KeyPress event to trap ASCII 10 or 13 and then set KeyAscii = 0. This is what I use to suppress certain characters or to substitute one character for another. ENTER doesn't seem to get trapped. Any suggestions on how I can handle this? I suppose I could allow the CRs, and convert them to spaces later on, but I'd prefer to have the user be aware at the time.

    Thanks,
    Richard Barrett

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: ENTER key / VBA (Word XP)

    Use the Key Down event:

    Private Sub TextBox1_KeyDown( _
    ByVal KeyCode As MSForms.ReturnInteger, _
    ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then
    KeyCode = 0
    End If
    End Sub

  4. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    861
    Thanks
    0
    Thanked 10 Times in 9 Posts

    Re: ENTER key / VBA (Word XP)

    Simple enough! Thank you.
    Richard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •