Microsoft KB Archive/188500

From BetaArchive Wiki

Article ID: 188500

Article Last Modified on 6/17/2005



APPLIES TO

  • Microsoft Excel 98 for Macintosh



This article was previously published under Q188500


SYMPTOMS

When you close a Microsoft Excel custom dialog box (UserForm), the RefEdit control of the UserForm may continue to appear in the foreground of the worksheet and any selected ranges of cells have a marquee around them. If there is a TextBox control on the form, any text typed while the insertion point is active in the TextBox control appears in the RefEdit control. Microsoft Excel cannot be closed and no menus are available, although you can still select ranges of cells on the spreadsheet.

CAUSE

This problem occurs when all of the following conditions are true:

  • A UserForm contains an OptionButton control with attached code to set the focus (SetFocus) to a RefEdit control on the same UserForm. -and-


  • The Value property of the OptionButton control is set to True in a Microsoft Visual Basic for Applications macro or procedure before the macro or procedure displays the UserForm using the Show method. -and-


  • The macro or procedure that shows the UserForm also sets the focus to another control (for example, a RefEdit control) on the UserForm after the Value property of the OptionButton control is set.


RESOLUTION

Microsoft 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. There are three methods for resolving this behavior.

Method 1: Changing the Order of the Lines of Code

In the Visual Basic macro or procedure that displays the UserForm, set the focus to another control before setting the Value property of the OptionButton control to True. The following example demonstrates this method:

  1. Open a new workbook in Microsoft Excel.
  2. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  3. On the Insert menu, click UserForm.
  4. If the Toolbox is not displayed, click Toolbox on the View menu.
  5. Drag an OptionButton, a RefEdit, a TextBox, and a CommandButton control to the UserForm from the Toolbox.
  6. Double-click the CommandButton control to see the Code window and type the following code:

            Private Sub CommandButton1_Click()
    
               UserForm1.Hide
               End
    
            End Sub
                            
  7. Close the code window.
  8. Double-click the OptionButton control to see the code window and type the following code:

            Private Sub OptionButton1_Click()
    
               UserForm1.RefEdit1.SetFocus
    
            End Sub
                            
  9. Close the code window.
  10. On the Insert menu, click Module.
  11. Type the following into the new module:

            Sub RunForm()
    
               With UserForm1
                  .TextBox1.SetFocus
                  .OptionButton1.Value = True
                  .Show
               End With
    
            End Sub
                            
  12. On the Tools menu, point to Macro, and then click Macros. Click RunForm, and then click Run.

    The macro will run and set the focus correctly.

Method 2: Do Not Set Focus with Code Attached to an OptionButton Control

Do not assign code to an OptionButton control to set the focus to a RefEdit control before a form is displayed. Instead, leave any OptionButton controls unselected to allow the user to make the choice.

Method 3: Do Not Set the Value Property of an OptionButton Control to True

Do not set the focus to another control in the procedure or macro that displays the UserForm if the same procedure or macro sets the Value property of the OptionButton control to True. Setting the Value property of the OptionButton control to True triggers the Click event procedure that is assigned to the OptionButton control.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.

REFERENCES

For more information about adding controls to a UserForm, from the Visual Basic Editor, click the Office Assistant, type Controls click Search, and then click to view "Adding Controls to a UserForm."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

176476 OFF: Office Assistant Not Answering Visual Basic Questions



Additional query words: cursor custom dialog box vbe text option command XL98 hang hangs hanging hung lock up locks locking locked lockup freeze freezes freezing froze frozen stop stopping stopped won't respond waiting

Keywords: kbbug kbprogramming kbdtacode kbpending KB188500