XL5: Macro Cannot Set Module to xlVeryHidden

ID: Q131551

The information in this article applies to:

SYMPTOMS

When you set the Visible property of a module to xlVeryHidden, you may receive the following error message:

   Macro Error 1005:
   Unable to set the Visible Property of the Module Class

CAUSE

This error will occur if the module that is being hidden contains a macro that is currently running.

WORKAROUND

If you would like to set the modules in a workbook to VeryHidden after you have finished creating them, follow these steps:

1. Insert a new module sheet by choosing Insert, Macro, Module from the

   menus.

2. Type the following example macro on the new module sheet:

      Sub HideModules()
        For each m in Modules
          If m.Name <> Activesheet.Name Then m.Visible = xlVeryHidden
        Next
      End Sub

3. While the new module is still the active sheet, run the HideModules
   macro by choosing Macro from the Tools menu. In the Macro Dialog Box,
   select the HideModules macro and choose Run.

4. After running the macro, all other modules will be hidden. Delete the
   new module by choosing Edit, Delete Sheet.

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

STATUS

This behavior is by design of the versions of Microsoft Excel listed at the beginning of this article.

MORE INFORMATION

In Microsoft Excel, setting the Visible Property of an object to xlVeryHidden hides the object so that it may only be unhidden by setting the Visible Property to True. For module sheets, this feature is primarily used to add a measure of protection to the macros in a workbook.

NOTE: You will also receive this error message in two other situations:

1. If the module you are trying to hide with the xlveryhidden property

   contains a variable declared as Public.

2. The module with the code to hide another module also calls a macro from
   the module it is trying to hide.

For more information about the xlVeryHidden property, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q128192
   TITLE     : XL5: Can't Insert Sheet Based on Template with Hidden Sheet

   ARTICLE-ID: Q128373
   TITLE     : XL5: Macro Cannot Determine If Sheet Is VeryHidden

   ARTICLE-ID:Q127944
   TITLE     : XL5: Sheet Based on Template with Hidden Sheet Not Inserted

REFERENCES

For more information about the Visible property, choose the Search button in Programming with Visual Basic Help and type:

   visible property

Additional query words: 5.00 very hidden XL5
Keywords          : kbprg 
Version           : WINDOWS:5.0,5.00c; MACINTOSH:5.0,5.0a
Platform          : MACINTOSH WINDOWS

Last Reviewed: May 17, 1999