Focus Method Doesn't Set Focus to Correct Dialog Control (129476)
The information in this article applies to:
- Microsoft Excel for Windows 95 7.0a
- Microsoft Excel for Windows 5.0c
- Microsoft Excel for the Macintosh 5.0a
This article was previously published under Q129476 SYMPTOMS
In Microsoft Excel, when you create a custom dialog box, if you use the
Focus method in a Microsoft Visual Basic for Applications procedure to set
the focus of the dialog box to a specific control, the control that you
specify may not have the focus when you display the dialog box.
CAUSE
This behavior occurs under the following conditions:
Microsoft Excel for the Macintosh- You set the focus of the dialog box to a control other than an edit box.
In Microsoft Excel for the Macintosh, you cannot set the focus of a dialog
box to a non-edit box, such as a button or drop-down box. This behavior is
by design of the user interface of the Macintosh.
Microsoft Excel for the Macintosh or for Windows- You did not assign the procedure that contains the Focus method to the
dialog frame.
The Focus property only works correctly when it is contained in a procedure
that is assigned to the dialog frame, or to a control in the dialog box. To
set the focus of the dialog box when the dialog box is displayed, you must
assign the procedure that contains the Focus method to the dialog frame.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this behavior in Microsoft Excel for the Macintosh, use the
Focus method to set the focus to an edit box in the dialog box, and assign
the procedure that contains the Focus method to the dialog frame.
To work around this behavior in Microsoft Excel for Windows, assign the
procedure that contains the Focus method to the dialog frame.
The following is an example of how to set the focus in a custom dialog box
using the Focus method in Microsoft Excel for either platform:
Example- Create a custom dialog box that contains two edit boxes, and a
combination drop-down edit control.
- In the dialog box, select the drop-down control, and note the name that
appears in the Name box, such as "Drop Down 5."
- From the Insert menu, choose Macro, and then choose Module. In the new
module, enter the following:
Sub Main()
DialogSheets(1).Show
End Sub
Sub DialogFrame1_Show()
' Note that the name used with the DropDowns method should
' be the name noted in Step 5 above.
ActiveDialog.Focus = _
DialogSheets(1).DropDowns("Drop Down 5").Name
End Sub
- Select the Dialog1 sheet tab, and select the dialog title. From the
Tools menu, choose Assign Macro. From the Macro Name/Reference list,
select DialogFrame1_Show, and choose OK.
- From the Tools menu, choose Macro. From the Macro Name/Reference list,
select Main, and choose Run.
Note that the drop-down edit box has the focus.
REFERENCES
For more information about the Focus property, choose the Search button in
MS Excel Visual Basic Help and type:
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbcode kbprb kbProgramming KB129476 |
---|
|