Results 1 to 4 of 4

Use info from class event, for Sub in userform

Threaded View

Un-Do Re-Do Use info from class event,... 07-10-2018, 10:22 AM
romperstomper Re: Use info from class... 07-10-2018, 10:45 AM
Arkadi Re: Use info from class... 07-10-2018, 10:46 AM
Un-Do Re-Do Re: Use info from class... 07-10-2018, 11:08 AM
  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Use info from class event, for Sub in userform

    How can the info from a class event be used as an argument for a Sub in a userform?
    In this example, there are multiple command buttons in a form, and 1 class module for all buttons. I want to write the Name of the command button, to a cell in Excel. The code to write to Excel must be in the form.
    My attempt to transfer the info is by "Call ThisSubInForm(MyButton.Name)" but it won't work.

    MODULE CODE
    Option Explicit
    
    Sub Form_OzG()
        UserFormOG.Show vbModeless
    End Sub
    FORM CODE
    Dim colButtons As New Collection
    
    Private Sub UserForm_Initialize()
        Dim ctl As MSForms.Control
        Dim obEvents As clsButtons
        For Each ctl In Me.Controls
            If TypeOf ctl Is MSForms.CommandButton Then
                Set obEvents = New clsButtons
                Set obEvents.MyButton = ctl
                colButtons.Add obEvents
            End If
        Next ctl
    End Sub
    
    Private Sub ThisSubInForm(Btn As String)
    Range("C4") = Btn
    End Sub
    CLASS MODULE
    Public WithEvents MyButton As MSForms.CommandButton
    
    Private Sub MyButton_Click()
    '    Call ThisSubInForm(MyButton.Name)
        Msgbox "You have clicked " & MyButton.Name
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [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
  2. AfterUpdate event in a Class Module
    By Mats Samson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-08-2012, 06:24 PM
  3. A Change class event
    By bagulhodoido in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2011, 03:13 AM
  4. create event in class module
    By x taol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2006, 10:40 PM
  5. Application Event in Class Module
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 08:50 PM
  6. [SOLVED] MsForms.Control Event Class
    By AikonEnohp via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2005, 09:05 PM
  7. [SOLVED] Further Clarification with Event Handlers & Class Modules
    By Kevin H. Stecyk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2005, 02:06 PM
  8. [SOLVED] Handling of event raised in other class module
    By VbaNew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2005, 09:06 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