+ Reply to Thread
Results 1 to 4 of 4

Resize Listbox with Function

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Resize Listbox with Function

    Hi all,

    I would like to use the following function to resize a listbox.

    Is it possible that this can be modified to run in VBA?

    Please Login or Register  to view this content.
    Code found at: http://www.freevbcode.com/ShowCode.Asp?ID=614
    Any help is appreciated.

    Thanks,

    BDB

  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,258

    Re: Resize Listbox with Function

    Hello BDB,

    Visual Basic exposes the window handles of its objects while VBA does not. The window handle, abbreviated in the API as hWnd, is important in controlling an objects properties and events. While it is possible to access the window handle of an object in VBA on a UserForm, the code is very complex and often not stable. While it is a nice idea, in VBA it is not practical to implement.
    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 Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Resize Listbox with Function

    Thanks Leith,

    With that being said, I still would like to use some method to resize the list.

    So, I've attempted to put together a function which seems to work to some extent. I have a few problems with it which I hope I can get resolved.

    Here's what I have, (along with commented out lines which are my holdbacks)

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    In my code, I set LB to listbox2 which is on sheet(1).

    If I try and carry LB to my Function , LB.name will show LB's name, but if if say
    LB.count it will error. Is there a way I can use my named object (LB) withing the Function other than just identifying the name?

    Once my Function does the calculation to listbox adjustment it returns a value to plug in
    which set the proper height. However, I'm still not always getting the height correctly adjusted for the number of items in the list. I don't know if it because my list is being built with directory names?

    Anyways any help is much appreciated.

    Thanks,

    BDB

  4. #4
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Re: Resize Listbox with Function

    For anyone wondering why I'm wanting to resize my list box. It's because with my mouse over event, the spacing distance (from the bottom of my last item to the bottom of listbox itself) is the spacing distance my mouse pointer is from being over the item being selected. If the box is adjusted to the size needed for the number of items in it, this
    weird phenomenon doesn't occur.

+ 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