+ Reply to Thread
Results 1 to 6 of 6

VBA Macros single event (Enter & Exit) for multiple userform textboxes

  1. #1
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Cool VBA Macros single event (Enter & Exit) for multiple userform textboxes

    Hello Again,

    I have around 197 textboxes on a single userform. I am trying to change backcolor & Font color when enter the textbox. and again change backcolor & Font color when enter the textbox.

    I have to write for each and ever textbox for enter/exit event. Can we have any solution to write single code for all the textboxes.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA Macros single event (Enter & Exit) for multiple userform textboxes

    Youe will have to declare a class and add the relevant textboxes as members of that class

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VBA Macros single event (Enter & Exit) for multiple userform textboxes

    nigelog, you can't do that. Enter and Exit are not exposed using WithEvents. You need to use some very creative workarounds or copy and paste the code a lot!

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,075

    Re: VBA Macros single event (Enter & Exit) for multiple userform textboxes

    Another option, though not much better, would be to create 2 subs & call them like
    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros single event (Enter & Exit) for multiple userform textboxes

    I found the below and it works for me after some minor changes. But still I have to write case statement for each and every textbox.

    Declaration
    Please Login or Register  to view this content.


    On Userform

    Please Login or Register  to view this content.



    ClassModule - Name:CtlExitCls
    Please Login or Register  to view this content.

  6. #6
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: VBA Macros single event (Enter & Exit) for multiple userform textboxes

    @Kyle
    Lol, glad I read that was wondering why it was not happening for me

+ 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. Textbox exit event prevents to exit userform
    By smjjvh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2014, 06:08 AM
  2. Texbox exit event prevents userform exit
    By smjjvh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2014, 05:47 AM
  3. [SOLVED] Userform multipage control - exit event not firing or event order
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 10:23 AM
  4. UserForm TB exit event
    By Jockster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2010, 02:36 PM
  5. How to tab or enter between textboxes not in userform
    By cuewoz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-02-2009, 03:10 AM
  6. [SOLVED] Exit Event with a single textbox control
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2006, 09:55 PM
  7. Close UserForm despite Exit Event
    By Carim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2005, 01:08 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