+ Reply to Thread
Results 1 to 4 of 4

Refer to userform objects in a macro

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Refer to userform objects in a macro

    Hi, Good morning all,

    So, simple question : Is it possible to refer to a userform objects like a ListBox from a macro example :

    The userform code could be :
    Private Sub CommandButton1_Click()
    call module1.Test
    End Sub
    And the macro code would be :
    Sub test
    If Listbox1.text = "blabla" then
    etc...
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Refer to userform objects in a macro

    Yes, you could do it a couple of ways, you could either create custom properties.

    something like this in the form

    Public Property Get ListBox1Value() as variant
             ListBox1Value=me.listbox1.value
    end property
    then reference,
    UserForm1.Listbox1Value
    or you can just open the form into an object and reference the object frm.listbox1.value.


    I am not in Excel at the mo, so cant properly test, but i'll post back in about 30mins.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Refer to userform objects in a macro

    Yes, you could do it a couple of ways, you could either create custom properties.

    something like this in the form

    Public Property Get ListBox1Value() as variant
             ListBox1Value=me.listbox1.value
    end property
    then reference,
    UserForm1.Listbox1Value
    or you can just open the form into an object and reference the object frm.listbox1.value.


    I am not in Excel at the mo, so cant properly test, but i'll post back in about 30mins.

  4. #4
    Registered User
    Join Date
    06-03-2014
    MS-Off Ver
    2007
    Posts
    87

    Re: Refer to userform objects in a macro

    Yes, I tried just stating the userform name before the object and it works.

    Ex :
    If UserForm1.ListBox1.Text = "Blabla" then
    Thank you for your help.

+ 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. Refer to add-in file name across objects and when name may change
    By el_guapo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2013, 07:37 PM
  2. [SOLVED] is it possible to make the objects movable on userform when userform is loaded.
    By yeshwant_sur in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-29-2012, 05:14 AM
  3. How to copy macro, userform, worksheet objects to new worksheets
    By Irony58 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-14-2012, 10:29 AM
  4. Refer to a worksheet from a userform
    By leonidas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2006, 07:45 AM
  5. refer to a userform in a formula
    By TimT in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-08-2005, 08:05 PM

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