XL Err Msg: Unable to Set the Text Property of Editbox Class

ID: Q130108


The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0


SYMPTOMS

When you run a Microsoft Visual Basic for Applications subroutine in Microsoft Excel, you may receive the following macro error message:

Runtime Error 1005:
Unable to Set the Text Property of the Editbox Class
This error will occur if the following conditions are true:

  • A macro attempts to set the Text property of an edit box on a protected dialog sheet


  • -and-

  • The workbook has been closed and reopened since protecting the dialog sheet


Note that this problem also occurs with check boxes (both on dialogs and also on worksheets).


CAUSE

To change the text of an edit box on a protected dialog sheet, the Lock Text check box must be cleared. The Lock Text check box is located on the Protection tab of the Format Object dialog box for that edit box. When the file is saved, closed, and reopened, the Lock Text check box is reset.


WORKAROUND

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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
To change the Text property of an edit box using a Visual Basic for Applications subroutine, use one of the following methods.

Method 1

Unprotect the dialog sheet before you change the edit box text and then reprotect the dialog sheet. The following example uses the Unprotect method to unprotect a dialog sheet named "Dialog1." It then changes the text of an edit box named "Edit Box 4," and then reprotects the Dialog Sheet.

    ' You can skip this line if you are adding this code to
   ' an existing macro.
   Sub ChangeEditBox()

      ' Unprotect the dialog sheet. If a password is required,
      ' remove the apostrophe in front of password and
      ' change "MyPassword" to the correct password.
      DialogSheets("Dialog1").Unprotect 'password:="MyPassword"

      ' Change the edit box text to "Hello." You should verify and
      ' change "Edit Box 4" to the correct name.
      DialogSheets("Dialog1").EditBoxes("Edit Box 4").Text = "Hello"

      ' Reprotect the worksheet. If a password is required,
      ' remove the apostrophe in front of password and change
      ' "MyPassword" to the correct password.
      DialogSheets("Dialog1").Protect 'password:="MyPassword"

   End Sub 

Method 2

Leave the dialog sheet unprotected.


STATUS

Microsoft has confirmed this to be a problem in versions of Microsoft Excel listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


REFERENCES

For more information about the Text Property, choose the Search button in Visual Basic Reference help and type:

Text Property
For additional information, please see the following articles in the Microsoft Knowledge Base:
Q113599 Can't Format Control Text in Objects Such As EditBox and Range
Q125422 XL5: Creating a Masked Password Dialog Box in Visual Basic

Additional query words: editbox dialogsheet checkbox

Keywords : kbcode kberrmsg kbprg PgmOthr
Version : MACINTOSH:5.0,5.0a; WINDOWS:5.0,5.0c,7.0; winnt:5.0
Platform : MACINTOSH WINDOWS winnt
Issue type : kbbug


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.