Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listbox Backcolor (Excel 2003 VBA)

    Hello,
    I am having some problems changing the backcolor of a listbox. I have a form with a bunch of controls (textboxes, combo boxes, listboxes, etc) that an end user will fill out. I made it so that the controls have a yellow background, and once they are filled out, they turn white. This works fine except on my listboxes. I entered the following code into both the _Change and _Click subroutines of the listboxes:
    listbox1.backcolor = vbWhite

    However the backcolor does not change. Any ideas as to why?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listbox Backcolor (Excel 2003 VBA)

    Try the AfterUpdate event of the list box.

  3. #3
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox Backcolor (Excel 2003 VBA)

    Thanks! I dont know why, but it worked!

  4. #4
    2 Star Lounger
    Join Date
    Sep 2003
    Location
    Toronto, Ontario, Canada
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox Backcolor (Excel 2003 VBA)

    Another problem:
    For some reason, after I run listbox_afterupdate(), it saves the listindex as the selection, but moves the highlight and display up to listindex 0... any ideas on how to circumvent that? I tried re-setting the listindex to the appropriate value, but it won't display it.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listbox Backcolor (Excel 2003 VBA)

    Apparently, setting either the forecolor or the backcolor of the list box causes problems with the highlight. I don't know how to prevent this. Would it be acceptable to change something else? E.g. the font name or the font style (you could set .Font.Italic = True, for example), or if you set the BorderStyle to Flat in design view, you can change the BorderColor in the AfterUpdate event.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •