+ Reply to Thread
Results 1 to 4 of 4

Userform Textbox - Cursor Position

  1. #1
    Registered User
    Join Date
    06-10-2014
    Posts
    21

    Userform Textbox - Cursor Position

    Hi All,

    I expect similar questions have been asked about this, so apologies if this has already been answered.

    Basically I want to return the position of the cursor when the mouse is clicked anywhere in a textbox.

    I know you can use SelStart, but what is causing me a problem is that it is not resetting for each line.

    Example text:

    Order No Description Qty Price
    ----------- -------------- ---- ------
    1234567 Item Name 1 12.00

    If I click the mouse between the "d" and "e" in the word "Order", SelStart returns 3, which is fine.

    However if I was to click the mouse between the "3" and "4" of the Order Number, I would still expect it to return 3 because its 3 characters from the left on that specific line, but SelStart returns the cursor position based on a count from the first character in the text box which is what I don't want.

    I can get the X position using CurLine, I'm just stuck on getting the Y position so that I can generate X and Y co-ordinates.

    It might be an obvious solution, but I'm having a bit of a mind blank and just can't see it, so any help would be appreciated.

    Thanks.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Userform Textbox - Cursor Position

    You need to take the CRLF at the end of each line into account.

    This example displays character to left of cursor, included any within a selection.
    You can see how the further down the lines you go the more it is out of sync.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-10-2014
    Posts
    21

    Re: Userform Textbox - Cursor Position

    Thanks for the help Andy.

    To give you a clearer picture of what I am trying to achieve, I want to replicate the function of the Text Import Wizard in Excel where you use the fixed width option and move the vertical indicators to define the columns.

    I'm not looking to add the vertical indicators or anything like that. I just want to be able to return a series of coordinates which would represent the column positions.

    The data is being retrieved from a text file and the only issue is that the headers aren't necessarily on row one of the file. If they were then using SelStart and SelLength on this row would give me the desired result. I think I may have answered my own question saying that. The data retrieved isn't saved or anything so I could simply remove any lines above the header so that line of data becomes the top row.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Userform Textbox - Cursor Position

    The workbook contains code to resolve the problem. But moving the row of data you are interested in to the top of the text box will also work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Cursor in a specific textbox in userform
    By RJ1969 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-21-2018, 01:58 AM
  2. Position cursor on refresh lisbox userform.
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-14-2014, 09:58 PM
  3. How can I show userform under the textbox position
    By cemregunay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2014, 09:23 PM
  4. Textbox: Change and determine cursor position
    By angela2009 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-05-2009, 07:17 AM
  5. position cursor on command button when userform opened
    By iturnrocks in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-09-2008, 01:19 PM
  6. [SOLVED] set cursor position to the last character of textbox
    By hapt285 in forum Excel General
    Replies: 0
    Last Post: 03-30-2006, 07:25 AM
  7. Move cursor to textbox in a userform
    By jgmiddel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2006, 09:55 AM

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