Article ID: 129476 - Last Review: June 11, 2007 - Revision: 2.3 Focus Method Doesn't Set Focus to Correct Dialog ControlThis article was previously published under Q129476 On This PageSYMPTOMS
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
Microsoft Excel for the Macintosh or for Windows
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
MORE INFORMATION
You can use the Focus property in a Visual Basic procedure to set the focus
of a dialog box that is displayed. The control on the dialog box that has
the focus is where user keyboard input is directed. The focus is indicated
by a flashing cursor or highlighted text within an edit box with the focus,
or, in Microsoft Excel for Windows only, by a dashed rectangle around the
control or around the selection within the control.
Note that you can also set the default focus of a dialog box when you create your dialog sheet. To do this, use the Tab Order dialog box (from the Tools menu, choose Tab Order). Note also that if you are using Microsoft Excel for the Macintosh, you can only set the tab order for edit boxes. REFERENCES
For more information about the Focus property, choose the Search button in
MS Excel Visual Basic Help and type:
focus in dialog boxes | Article Translations
|

Back to the top
