Use of dialogs in Excel

I want a dialog box with a combo box enumerating all worksheets in a workbook in Excel97. I want to call this dialog from a macro and get the result so I can then reference the correct worksheet.

I have found out how to draw dialogs, but I don't understand at all about how to actually use a dialog!

I am looking for a solution, but if people can point me to a good tutorial towards doing stuff like this, I would be grateful.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


1. Create a UserForm with a combo box and a commandbutton.

2. Double-click the commandbutton and add this code:

Private Sub CommandButton1_Click()
End Sub

Private Sub UserForm_Initialize()
  Dim ws As Worksheet
  For Each ws In ActiveWorkbook.Worksheets
    ComboBox1.AddItem ws.Name
  Next ws
End Sub

3. Create a new module (Insert - Module) and add this code:

Sub TestForm()
  Dim s As String
  s = UserForm1.ComboBox1.Text
  MsgBox s
  Unload UserForm1
End Sub

Done. When running the TestForm procedure, this will happen:

1. The form is initialized
2. Before the form actually shows on screen, the combobox is loaded with all worksheet names
3. You select a worksheet from the combobox and click the commandbutton
4. The form is hidden and control is returned to the TestForm procedure
5. The variable s gets the combobox text
6. The form is unloaded
7. s is displayed in a message box

Ture Magnusson
Karlstad, Sweden

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AstromanAuthor Commented:
Cheers, that was exactly what I need to know.

It's funny, but I was getting pretty close, but I have nothing really to work from except the MSDN site, which doesn't seem much good for a beginner.

I thought there must have been an easier way to deal with dialogs other than writing loads of event handlers and stuff - thanks for showing me how.

Leon (aka Astroman!)
You are welcome, Leon! I'm glad that I could help you.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.