+ Reply to Thread
Results 1 to 12 of 12

Add quotes to textbox and move cursor between them

  1. #1
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Add quotes to textbox and move cursor between them

    Hi...trying to figure out the best way to add quotation marks to a text box (which is on a sheet, not a userform) then move the cursor back one position between them.

    I can add them fine (the line below takes whatever string is already in the textbox, called InstructionsBox, and adds two double quotes to the end:

    Please Login or Register  to view this content.
    Now I think I need to set focus back to the textbox and move the cursor back between the quotation marks. The SetFocus method isn't available (though SELECT is), and my sorry attempt at using a send key isn't working either

    This seems so simple, but I just can't get it to work... any help is appreciated.
    Last edited by JP Romano; 12-29-2010 at 05:45 PM. Reason: SOLVED

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Add quotes to textbox and move cursor between them

    Hello JP,

    Is this a Controls Toolbox control?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    I believe he added it using the Active X controls (in Excel 2007) ... from the developers tab, design mode / Insert / text box (from the Active X section)

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Add quotes to textbox and move cursor between them

    Hello JP,

    Add this code to the TextBox's GotFocus event on the worksheet. Be sure to change the name of the TextBox to match yours.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    Thanks Leith... really appreciate it.
    I actually added it to another button, which the user will click to add the quotes (otherwise, anytime a user clicks in the box, they'd get the quotation marks -- instead of only when they need them.

    What I'm not able to do yet, though, is get the focus back to where the cursor is between the quotation marks.

    This may sound vague, so I'm going to attach a sample sheet from the workbook. Please ignore the rudimentary coding... much is experimental.

    If you do check it out, the code in question is under sheet4, Private Sub AddQuote_Click.
    Thanks again for your expert guidance!

    JP

  6. #6
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    I see my attachment didn't come through...trying again...
    Attached Files Attached Files

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Add quotes to textbox and move cursor between them

    Hello JP,

    Change you button code to this...
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 12-29-2010 at 05:43 PM.

  8. #8
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    That's absolutely perfect... exactly what I was after. Thanks a million Leith!

  9. #9
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    Wait, one small problem...dang.
    If the text in the text box is a single string, it works perfectly, but if the user has multiple lines, the cursor doesn't return between the quotes.
    For example, enter
    Line1 (hard return)
    Line2
    Then click the "" button.
    If this is a big deal, please don't spend any time on it... but if there's a quick fix, like some way to add an if statement to detect the hard return, then adjust the -1 to -2, I'm game!

  10. #10
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    I figured it out - this seems to be working!
    Please Login or Register  to view this content.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Add quotes to textbox and move cursor between them

    Hello JP,

    Good job! I didn't think to ask about multiple lines in the TextBox. I thought the text would be wrapped automatically.

  12. #12
    Forum Contributor JP Romano's Avatar
    Join Date
    10-09-2008
    Location
    Princeton, NJ
    MS-Off Ver
    2010
    Posts
    500

    Re: Add quotes to textbox and move cursor between them

    Thanks for your help Leith... by the way, it's not chr(34) it's chr(10) for the returns - stupid mistake. Seems to be working quite nicely now, thanks to you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1