+ Reply to Thread
Results 1 to 4 of 4

Trying to access ListBox object programmatically

  1. #1
    Registered User
    Join Date
    02-25-2010
    Location
    King of Prussia, PA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Trying to access ListBox object programmatically

    I have a userform in the current project named MIGForm, with a ListBox names ListBox1.
    In the procedure below, the first Debug.Print line works as it should -- it returns "ListBox" -- so I know that MIGForm.ListBox1 exists and is a listbox. Yet the "Set" line below fails. Would anyone be able to explain why?

    The reason this is relevant is that I have written a sub that takes a listbox as an argument and populates it with the elements of a range argument. It would be so convenient to be able to use this, but VBA will not let me use my userform list boxes as arguments to this function.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 12-17-2010 at 01:24 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to access ListBox object programmatically

    Hello JGPatrick,

    The code should work if the your userform is loaded. If the user is not loaded then macro will not work.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Trying to access ListBox object programmatically

    Please Login or Register  to view this content.



  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,021

    Re: Trying to access ListBox object programmatically

    Change the dim statement to:
    Please Login or Register  to view this content.
    assuming the error you were getting was 13 type mismatch.
    Everyone who confuses correlation and causation ends up dead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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