Populating Userform ComboBox with worksheet names in XL2003

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to populate a ComboBox located in a userform with all of the
worksheet names in the workbook. I'm having problems getting this to work.
I found the following code in an earlier post, but no success:

for each sh in activeworkbook.sheets
combobox1.additem sh.name
next

How do I do this and where should the lines of code be located in the
overall code? What kind of sub procedure is this in (if any)?

Thanks for your help! (I'm very new to VBA and am learning as I go...)

-Mark
 
in the userform module, in the upper left dropdown select Userform and in
the Upper right dropdown select Initialize

Private Sub Userform_Initialize()

End Sub

will appear in the module. Put the code there

Private Sub Userform_Initialize()
Dim sh as worksheet
for each sh in activeworkbook.worksheets
me.combobox1.additem sh.name
next
End Sub

This event will fire whenever the userform is created.
 
Back
Top