Article ID: 141685
Article Last Modified on 10/11/2006
Control type Control name ------------------------------------------------------------------------ Label Label 4 Edit box Edit Box 5 Button Button 6 Check box Check Box 7 Option button Option Button 8 List box List Box 9 Drop-down (or Combo Box) Drop Down 10 Scroll bar Scroll Bar 11 Spinner Spinner 12
Sub test()
' Dimension variables.
Dim diag As Object
Dim wkst As Object
Dim x As Integer
Dim counter As Integer
' Set objects.
Set diag = DialogSheets("Dialog1")
Set wkst = Worksheets("Sheet1")
' Clear edit box, drop-down list, and list box.
diag.EditBoxes("Edit Box 5").Text = ""
diag.ListBoxes("List Box 9").RemoveAllItems
diag.DropDowns("Drop Down 10").RemoveAllItems
' Set spinner and scrollbar back to 0.
diag.ScrollBars("Scroll Bar 11").Value = 0
diag.Spinners("Spinner 12").Value = 0
' Insert data into list box and drop-down list.
myarray = Array("Tom", "Fred", "Sam", "Wilma", "Sandy")
For x = 0 To 4
diag.ListBoxes("List Box 9").AddItem myarray(x)
diag.DropDowns("Drop Down 10").AddItem myarray(x)
Next x
' Clear the edit box.
diag.EditBoxes("Edit Box 5").Text = ""
' Set spinner and scrollbar back to 0
diag.ScrollBars("Scroll Bar 11").Value = 0
diag.Spinners("Spinner 12").Value = 0
' Show Custom Dialog Box.
diag.Show
counter = 1
' Loop through controls on dialog and return name
' and value or caption to Sheet1.
' OK button is 1 and Cancel button is 2.
For x = 3 To 11
' Place name of control in column A.
wkst.Cells(counter, 1) = diag.DrawingObjects(x).Name
Select Case diag.DrawingObjects(x).Name
Case "Label 4"
wkst.Cells(counter, 2) = diag.Labels("Label 4").Caption
Case "Edit Box 5"
' Check control to see if it is blank. If it
' is blank, change the font to red.
If diag.EditBoxes("Edit Box 5").Text = "" Then
wkst.Cells(counter, 2) = "You Left This Control Empty"
wkst.Range("B" & counter).Font.ColorIndex = 3
Else
wkst.Cells(counter, 2) = _
diag.EditBoxes("Edit Box 5").Text
End If
Case "Button 6"
wkst.Cells(counter, 2) = diag.Buttons("Button 6").Caption
Case "Check Box 7"
' If the value is 1, option was selected.
' If the value is not 1, it is blank.
If diag.CheckBoxes("Check Box 7").Value = 1 Then
wkst.Cells(counter, 2) = "On"
Else
wkst.Cells(counter, 2) = "Off"
End If
Case "Option Button 8"
' If the value is 1, option was selected.
' If the value is not 1, it is blank.
If diag.OptionButtons("Option Button 8").Value = 1 Then
wkst.Cells(counter, 2) = "On"
Else
wkst.Cells(counter, 2) = "Off"
End If
Case "List Box 9"
' Check control to see if it is blank. If so, change font
' to red.
If diag.ListBoxes("List Box 9").ListIndex = 0 Then
wkst.Cells(counter, 2) = "You Left This Control " _
& "Empty."
wkst.Range("B" & counter).Font.ColorIndex = 3
Else
wkst.Cells(counter, 2) = _
diag.ListBoxes("List Box 9").List _
(diag.ListBoxes("List Box 9").ListIndex)
End If
Case "Drop Down 10"
' Check control to see if it is blank. If so, change the
' font to red.
If diag.ListBoxes("List Box 9").ListIndex = 0 Then
wkst.Cells(counter, 2) = "You Left This Control " _
& "Empty."
wkst.Range("B" & counter).Font.ColorIndex = 3
Else
wkst.Cells(counter, 2) = diag. _
DropDowns("Drop Down 10").List _
(diag.DropDowns("Drop Down 10").ListIndex)
End If
Case "Scroll Bar 11"
wkst.Cells(counter, 2) = _
diag.ScrollBars("Scroll Bar 11").Value
Case "Spinner 12"
wkst.Cells(counter, 2) = _
diag.Spinners("Spinner 12").Value
End Select
' Increment counter.
counter = counter + 1
Next x
' Select Sheet1.
wkst.Activate
' Autofit columns.
Columns("A:B").Select
Selection.Columns.AutoFit
Range("a1").Select
End Sub
A1: Label 4 B1: Label 4
A2: Edit Box 5 B2: You Left This Control Empty.
A3: Button 6 B3: Button 6
A4: Check Box 7 B4: On
A5: Option Button 8 B5: On
A6: List Box 9 B6: Wilma
A7: Drop Down 10 B7: Fred
A8: Scroll Bar 11 B8: 1
A9: Spinner 12 B9: 1controls
returning data from a control
Additional query words: xl97 dialog dialogsheet worksheet controls combobox dropdown listbox editbox optionbutton scrollbar XL
Keywords: kbdtacode kbhowto kbprogramming KB141685