+ Reply to Thread
Results 1 to 11 of 11

Access manually added ListBox in VBE

  1. #1
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Access manually added ListBox in VBE

    Hi,

    I'm trying to simply create a listbox by Developer > Insert > ListBox and then I want to access said listbox through the VBE to perform actions on it. How do I initialize the listbox from VBE? I don't want to select a range to fill the list. And even if i do, where do i put my code that tells the listbox to perform actions based what is beeing highlighted?

    I've tried this (in my Module1):
    Please Login or Register  to view this content.
    But this gives me the "object required error".

    Thanks for any help!

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Access manually added ListBox in VBE

    once you add the listbox right click it and choose View Code. you can then use the dropdown on the left of the module window to select Listbox1 and the dropdown on the right lists all the available events. you can also right click the control and choose Properties to set design time properties such as the listfillrange
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: Access manually added ListBox in VBE

    Thanks for the help!

  4. #4
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: Access manually added ListBox in VBE

    Quote Originally Posted by JosephP View Post
    once you add the listbox right click it and choose View Code. you can then use the dropdown on the left of the module window to select Listbox1 and the dropdown on the right lists all the available events. you can also right click the control and choose Properties to set design time properties such as the listfillrange
    I actually didn't try this until now and it doesn't work for me. As far as i know there is no "view code" on Excel for Mac 2011? I've looked through all modules and all sheets, can't find the listbox object anywhere.. :S

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Access manually added ListBox in VBE

    my bad-didn't notice you were on a mac so you aren't using an activex listbox and can't access its properties in the vbe
    you can refer to it using
    Please Login or Register  to view this content.
    note that it does not have a Text property-you have to use Value or Listindex both of which return the position of the selected item in the list starting at 0 for the first item

  6. #6
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: Access manually added ListBox in VBE

    Finally! Wow this helps SO MUCH! Thank you!
    I'm kind of using different computers on and off, one being a mac and one being a pc, is it easier to work with a activex listbox? Can I use the "Text" function with a activex listbox? (Don't have access to the pc atm, so can't try it myself)
    Having some issues with working with the listbox in the sheet, can't get it to work as my userform listboxes.. I just want to perform some actions based on what's highlighted in the listbox. How do i write a macro that reacts to "clicks" when it's not in a userform? messed around a bit:
    Please Login or Register  to view this content.
    But that wouldn't work. How does it work?
    Last edited by vizzkid; 03-23-2013 at 08:39 AM.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Access manually added ListBox in VBE

    you assign a macro to the listbox but note what I said before: you have to use Value or Listindex both of which return the position of the selected item in the list starting at 0 for the first item

  8. #8
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: Access manually added ListBox in VBE

    I still don't quite understand.. Let's say I assign the above test() macro to the listbox, what do i "try" my if statement on?
    Still
    Please Login or Register  to view this content.
    ??

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Access manually added ListBox in VBE

    if TEST is the first item then
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    03-04-2013
    Location
    Europe
    MS-Off Ver
    Office 365 ProPlus
    Posts
    147

    Re: Access manually added ListBox in VBE

    Hehe slightly embarressed now that i didn't understand from your first reply.. But thank you very much for your help!

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Access manually added ListBox in VBE

    you're welcome :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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