Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: RefEdit Control Still Appears After You Close UserForm


View products that this article applies to.

This article was previously published under Q213673

↑ Back to the top


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 you type 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 worksheet.

↑ Back to the top


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.

↑ Back to the top


Resolution

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS To resolve this behavior, use one of the following three methods.

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 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 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 runs and sets 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 not selected 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.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

If the behavior occurs, you may be able to get out of the situation without having to quit Microsoft Excel in the Close Program dialog box. However, this is possible only if the Visual Basic Editor is running. Follow these steps to avoid having to quit Microsoft Excel:
  1. Close the UserForm.
  2. On the Microsoft Windows 2000 taskbar, click the Visual Basic Editor button.
  3. In the Visual Basic Editor, click the Reset button on the Standard toolbar to end the macro.
  4. Press CTRL+ALT+DELETE to display the Close Program dialog box.
  5. Click Microsoft Visual Basic - workbook.xls (running) (where workbook.xls is the name of your file).
  6. Click End Task.

    This will close the Visual Basic Editor. An error message then appears that states:
    Cannot quit Microsoft Excel.
  7. Click OK.

    The Microsoft Visual Basic - workbook.xls (running) dialog box appears.

    It states that the program is not responding.
  8. Click Cancel.

    The RefEdit control may appear in a collapsed UserForm window over the spreadsheet now with a range address in it.
  9. Click the Close button in the collapsed UserForm.

    You should now be able to restart the Visual Basic Editor and continue editing your program.

↑ Back to the top


References

For additional information about getting help with Visual Basic forApplications, click the article number below to view the article in the Microsoft Knowledge Base:
226118� OFF2000: Programming Resources for Visual Basic for Applications

↑ Back to the top


Keywords: KB213673, kbprogramming, kbpending, kbdtacode, kbbug

↑ Back to the top

Article Info
Article ID : 213673
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 313