{"id":14070811,"url":"https://github.com/todar/VBA-Userform-EventListener","last_synced_at":"2025-07-30T08:32:36.850Z","repository":{"id":122243709,"uuid":"174034206","full_name":"todar/VBA-Userform-EventListener","owner":"todar","description":"🎉 A very easy way to add event listeners to a userform.","archived":false,"fork":false,"pushed_at":"2021-08-17T20:56:20.000Z","size":84,"stargazers_count":26,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-13T07:18:19.534Z","etag":null,"topics":["eventlistener","events","userform","vba"],"latest_commit_sha":null,"homepage":"https://www.roberttodar.com/","language":"VBA","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/todar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://www.buymeacoffee.com/todar"]}},"created_at":"2019-03-05T23:06:37.000Z","updated_at":"2024-06-21T05:28:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"540ff580-9ec1-462d-ac33-61abf85d3193","html_url":"https://github.com/todar/VBA-Userform-EventListener","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todar%2FVBA-Userform-EventListener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todar%2FVBA-Userform-EventListener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todar%2FVBA-Userform-EventListener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/todar%2FVBA-Userform-EventListener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/todar","download_url":"https://codeload.github.com/todar/VBA-Userform-EventListener/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228110841,"owners_count":17871243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eventlistener","events","userform","vba"],"created_at":"2024-08-13T07:08:06.519Z","updated_at":"2024-12-04T12:32:19.918Z","avatar_url":"https://github.com/todar.png","language":"VBA","funding_links":["https://www.buymeacoffee.com/todar"],"categories":["VBA"],"sub_categories":[],"readme":"# VBA Userform EventListener\n\nA very easy way to add event listeners to a userform.\n\n\u003ca href=\"https://www.buymeacoffee.com/todar\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" style=\"height: 51px !important;width: 217px !important;\" \u003e\u003c/a\u003e\n\n## Getting Started\n\u003e Importing or copying both **EventListenerEmitter.cls** and **EventListenerItem.cls** is **required** in order to work!\n\nHere is a basic template, simply add this to a userform.\n```vb\nPrivate WithEvents Emitter As EventListenerEmitter\n\nPrivate Sub UserForm_Activate()\n    Set Emitter = New EventListenerEmitter\n    Emitter.AddEventListenerAll Me\nEnd Sub\n```\n\nThat's it, now you can start listening for events!\n\n## Listening for the events\n\nYou can listen for all events in one event handler **Emitter_EmittedEvent** or each individual controls events. see the example below.\n\n```vb\n' EXAMPLE SHOWING A BASIC WAY OF DOING A HOVER EFFECT\nPrivate Sub Emitter_EmittedEvent(Control As Object, ByVal EventName As EmittedEvent, EventParameters As Collection)\n    ' Select statements are really handy working with these events in this way.\n    Select Case True\n        ' Change color when mouseover, for a fun hover effect :)\n        Case EventName = MouseOver And TypeName(Control) = \"CommandButton\"\n            Control.BackColor = 9029664\n\n        ' Don't forget to change it back!\n        Case EventName = MouseOut And TypeName(Control) = \"CommandButton\"\n            Control.BackColor = 8435998\n    End Select\nEnd Sub\n```\n\nYou can also listen just to specific events as well.\n\n```vb\nPrivate Sub Emitter_Focus(Control As Object)\n    ' CHANGE BORDER COLOR FOR TEXTBOX TO A LIGHT BLUE\n    If TypeName(Control) = \"TextBox\" Then\n        Control.BorderColor = 16034051\n    End If\nEnd Sub\n\nPrivate Sub Emitter_Blur(Control As Object)\n    ' CHANGE BORDER COLOR BACK TO A LIGHT GREY\n    If TypeName(Control) = \"TextBox\" Then\n        Control.BorderColor = 12434877\n    End If\nEnd Sub\n```\n\nOr you can listen to specific events on specific controls\n\n```vb\nPrivate Sub Emitter_CommandButtonMouseOver(CommandButton As MSForms.CommandButton)\n    CommandButton.Backcolor = 9029664\nEnd Sub\n\nPrivate Sub Emitter_CommandButtonMouseOut(CommandButton As MSForms.CommandButton)\n    CommandButton.Backcolor = 8435998\nEnd Sub\n```\n\n## Note\nThis is in the early stages, so feel free to use it as you wish. Currently, the events emitted are pretty simple: Click, DoubleClick, MouseOver, MouseOut, MouseMove, MouseDown, and MouseUp. \n\nAs I have time I'll be adding more events and seeing if I have any needed improvements.\n\nFeel free to do a pull request if you added to it or improved it in any way!\n\n**Also, I've posted this code on \u003ca href=\"https://codereview.stackexchange.com/questions/220370/userform-event-listener-and-emitter\"\u003ecodereview\u003c/a\u003e. Feel free to make suggestions or improvements there as well!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftodar%2FVBA-Userform-EventListener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftodar%2FVBA-Userform-EventListener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftodar%2FVBA-Userform-EventListener/lists"}