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

Last reviewed: December 1, 1997
Article 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 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 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/refguide/default.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:

   ARTICLE-ID: Q113599
   TITLE     : Can't Format Control Text in Objects Such As EditBox and
               Range

   ARTICLE-ID: Q125422
   TITLE     : XL5: Creating a Masked Password Dialog Box in Visual Basic


Additional query words: editbox dialogsheet checkbox
Keywords : kbcode kberrmsg kbprg PgmOthr
Version : WINDOWS: 5.0,5.0c,7.0; MACINTOSH: 5.0,5.0a
Platform : MACINTOSH WINDOWS
Issue type : kbbug
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.