[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Use of dialogs in Excel

Posted on 1999-10-26
3
Medium Priority
?
175 Views
Last Modified: 2010-05-02
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.

Leon
0
Comment
Question by:Astroman
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
ture earned 240 total points
ID: 2161612
Astroman,

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

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

Private Sub CommandButton1_Click()
  Me.Hide
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
  UserForm1.Show
  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
0
 
LVL 1

Author Comment

by:Astroman
ID: 2163103
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!)
0
 
LVL 22

Expert Comment

by:ture
ID: 2163177
You are welcome, Leon! I'm glad that I could help you.

/Ture
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question