XL97: Limitations for Naming Visual Basic Modules

Last reviewed: March 9, 1998
Article ID: Q158632
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SUMMARY

In Microsoft Excel 97, the names of Visual Basic for Applications modules are subject to certain limitations. This article explains these limitations how to avoid problems when module names include illegal characters.

MORE INFORMATION

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/supportnet/refguide/

Changing the Name of a Module in Microsoft Excel 97

In Microsoft Excel 97, you can rename a module by activating the module, clicking to the right of "(Name)" in the Properties window of the Visual Basic Editor, typing a new module name, and pressing ENTER.

You can also programmatically change the name of a module by using code similar to the following:

   ActiveWorkbook.Modules("Module1").Name = "Module7"

Limitations for Naming Modules in Microsoft Excel 97

In Microsoft Excel 97, module names can include the following characters:

  • Alphanumerics (A-Z, a-z, 0-9)
  • Underscore characters (_)

Illegal characters (characters that cannot be used in module names) include the following:
  • Spaces ( )
  • Exclamation points (!)
  • Periods (.)
  • Question marks (?)
  • Commas (,)
  • Any other nonalphanumeric characters

NOTE: Some characters that are illegal in Microsoft Excel 97 are acceptable in earlier versions of Microsoft Excel.

Module names cannot exceed 31 characters in length.

Module names cannot start with a numeric character (0-9) or an underscore character (_). Module names must start with an alphabetical character (A-Z, a-z).

If you try to rename a module so that its name includes illegal characters, you will receive the following error message:

   Not a legal object name: '<module name>'

where <module name> is the name of the active module sheet.

Names of Modules That You Created in Earlier Versions of Microsoft Excel

If you open a workbook that contains modules with names that include characters that are illegal in Microsoft Excel 97, the modules and the macros they contain are still available.

None of the modules are renamed by Microsoft Excel 97. However, if a module's name contains an exclamation point, the exclamation point is replaced on the screen by a question mark. However, the actual name of the module does not change.

For example, if you open a Microsoft Excel 5.0 or 7.0 workbook that contains the following three modules, Microsoft Excel 97 may change the module names. The following table illustrates how the module names would appear.

   Original             Module name that appears
   module name          in the Project Window
   ---------------------------------------------

   Module!1             Module?1
   My Module            My Module
   xyz.Module           xyz.Module

Microsoft strongly recommends that you rename such modules so that their names do not include any illegal characters. For example, in the table above, rename the module from Module!1 to Module1 or Module_1.

For more information, see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q159465
   TITLE     : XL97: "Module not Found" Error Opening Workbook

Note that renaming modules may require that you modify your Visual Basic macro code wherever it refers to a module by name.

Exporting or Importing Modules with Names That Contain Illegal Characters

In Microsoft Excel 97, you can export a Visual Basic module to a separate file by activating the module and clicking Export File on the File menu. This works even if the module name includes illegal characters.

However, when you click Import File on the File menu and attempt to import a file, you may receive the following error message:

   Not a legal object name: '<module name>'

where <module name> is the name of the module.

This problem occurs if the VB_Name attribute in the file contains any illegal characters.

To prevent this problem from occurring, use the following steps:

  1. On the Start menu, click Run. In the Open box, type "Notepad" (without the quotation marks), and click OK.

  2. In Notepad, click Open on the File menu. Select the file you want to import into Microsoft Excel, and click Open.

    The first line of the file should look similar to the following example:

          Attribute VB_Name = "Module 1"
    

  3. Change the name inside the quotation marks to a name that does not contain any illegal characters. For example, use Module1 or Module_1.

  4. When you are done, click Save on the File menu. Then, click Exit on the File menu.

NOTE: If your Visual Basic module is very large, you may need to edit it using Wordpad or another text editor.


Additional query words: XL97
Keywords : kbprg kbdta kbdtacode xlvbainfo xlui xl97vbmigrate
Version : WINDOWS:97
Platform : WINDOWS


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: March 9, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.