0

I have an Excel2010 VBA userform that has one comboBox, from which the user should be able to select a currently-open Excel Workbook. The USERFORM_Initialize subroutine contains (among other things) :

    cbWorkbook.Clear
    cbWorkbook.Visible = True
    For Each wb In Workbooks
        cbWorkbook.AddItem wb.name
    Next wb

I have set a breakpoint at this code, and am able to step through it; in the present situation there are four open workbooks, and the "for each" is iterated four times, as appropriate. And I can see that wb.name contains the values that I want.

However, when the form displays and the dropbox arrow is clicked, the "list" is empty. It looks like there is room for one item, and that item is blank. (I believe this is typical of an empty dropdown box.)

Select attributes for the combobox are: Autosize=False; AutoTab=false; Enabled=True; DropButtonStyle=1-fmDropButtonStyleArrow; Height=18; ListRows=8; ListStyle=0; Locked=False; ShowOptionWhen=2; SpecialEffect=2; Style=0; Visible=True. At the time of execution, cbWorkbook.listCount = 4

This is in development, and it did appear to work as expected yesterday, but now seems to never work. Any ideas where I might be going wrong?

EDIT: I found the solution to this: I had inadvertantly duplicated another combo box over the top of cbWorksheet, effectively hiding it. The control I was seeing was empty, while the control I wanted was overlaid. Deletion of the rogue control box solved the issues.

My apologies; this should have been the first thing I sought.

5
  • Do you have any error handling? Commented Mar 8, 2012 at 16:31
  • No error handling anywhere in this workbook at this time. Commented Mar 8, 2012 at 18:31
  • Can you post the full code for the userform? Commented Mar 9, 2012 at 9:19
  • If you have discovered your own solution, you should post it as an answer and then accept it so others can more easily identify it in the future. Commented Mar 9, 2012 at 14:51
  • Thanks. I have done that now. Commented Mar 11, 2012 at 17:21

2 Answers 2

1

I found the solution to this: I had inadvertantly duplicated another combo box over the top of cbWorksheet, effectively hiding it. The control I was seeing was empty, while the control I wanted was overlaid. Deletion of the rogue control box solved the issues.

My apologies; this should have been the first thing I sought.

Sign up to request clarification or add additional context in comments.

Comments

0
With ComboBox1
   .AddItem "This"
   .AddItem "Is"
   .AddItem "A"
   .AddItem "Test"
End With

or if you want to fill it with Range data:

ActiveSheet.Shapes("ComboBox1").Select
Selection.ListFillRange = "k1:k10"

PS - submit your file for review; it should be easier to look at!

1 Comment

Sorry... how do I submit it for review?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.