+ Reply to Thread
Results 1 to 11 of 11

TextBox_BeforeUpdate, TextBox_Change

  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    TextBox_BeforeUpdate, TextBox_Change

    I have a userform that takes cell contents, allows editing in the userform and transfers contents back to the cell as you type. The font is preserved as well.
    It works except for the instance described: If part of the string is selected/highlighted and the user types in character/s to overwrite the text, the fonts are lost.
    I wanted to account for this by using the ".SelLength" property to back-calculate the fonts (.SelLength counts the number of characters highlighted).
    The issue is that the information is lost on a "TextBox_Change" event (.SelLength goes to zero).
    I have tried to resolve by using the "TextBox_BeforeUpdate" method but don't know how to do it.

    Will it be possible?


    FORM CODE
    Please Login or Register  to view this content.
    CLASS MODULE clsTextBox
    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: TextBox_BeforeUpdate, TextBox_Change

    BeforeUpdate would be far too late. You could try a Keydown event instead.
    Rory

  3. #3
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    I will leave out BeforeUpdate then.
    With the Keydown event, I need help with the code.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: TextBox_BeforeUpdate, TextBox_Change

    Thikning about it, KeyPress is probably simpler to use. In your class you'd use:

    Please Login or Register  to view this content.
    which would allow you to store the selection length in a variable for use by your change event, if required.

  5. #5
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    This has given me something to work with. I will spend some time looking into it further.

  6. #6
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    How can I pass the value of "MyTextBox.SelLength" in the class module to the code in the form (to "Sub transfer()").

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: TextBox_BeforeUpdate, TextBox_Change

    Add a parameter to the Transfer sub and pass it directly.

  8. #8
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    But how sir?

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: TextBox_BeforeUpdate, TextBox_Change

    I guess you didn't write this code?

    Like this:

    Please Login or Register  to view this content.
    then:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    Thank you very much.
    Yes, most of the code is written by others.

  11. #11
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: TextBox_BeforeUpdate, TextBox_Change

    See the attached for solution.
    I have two change events in the class module, one as per post #9. I had to use two Subs to transfer.
    Attached Files Attached Files

+ 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] textbox_change : no find do nothing
    By mabulco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-12-2013, 07:37 AM

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