OFF97: Visual Basic Modules Cannot Be Hidden or Protected

Last reviewed: February 27, 1998
Article ID: Q156879
The information in this article applies to:
  • Microsoft Excel 97 for Windows
  • Microsoft Word 97 for Windows
  • Microsoft PowerPoint 97 for Windows

SYMPTOMS

In the programs listed at the beginning of this article, you cannot hide or protect a module either manually or by using a macro.

CAUSE

This behavior is by design of the programs listed above. In earlier versions of Microsoft Excel, macro sheets and Visual Basic modules are contained on tabs in a workbook. These tabs can be hidden or protected manually or using the Visible, Protect, or Unprotect commands in a macro.

However, in Microsoft Excel 97, Microsoft Word 97, and Microsoft PowerPoint 97, Visual Basic modules are displayed in the Visual Basic Editor. Modules in the Visual Basic Editor cannot be hidden or protected in the same way that they were hidden or protected in earlier versions of Microsoft Excel.

WORKAROUND

To hide or protect a module in Microsoft Excel 97, create an add-in file. When you open an add-in file, it is not possible to view the module it contains, and code in the add-in cannot be viewed or modified.

To make an add-in file in Microsoft Excel 97, follow these steps:

  1. In the Visual Basic Editor, click <Project Name> Properties on the Tools menu, where <Project Name> is the name of the project for which you are creating an add-in.

  2. Click the Protection tab.

  3. Click the "Lock Project for Viewing" check box. Type a password in the Password box, and then type the password again in the Confirm Password box.

  4. Click OK.

  5. On the File menu, click "Close and Return To Microsoft Excel."

  6. In Microsoft Excel, click Save As on the File menu.

  7. In the Save As Type box, click Microsoft Excel Add-In.

    If you want to change the name of the file, change it in the File Name box.

  8. Click Save.

Note that if you open the add-in, no window appears, and you cannot unhide the add-in. To view a module in the add-in, follow these steps:

  1. On the Tools menu, point to Macro, and then click Visual Basic Editor.

  2. In the Visual Basic Editor, click the entry for the add-in in the Project pane.

  3. When you are prompted, type the password for the add-in, and then click OK.

You can now view a module in the add-in and make changes to your macro code.

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/support/supportnet/refguide/default.asp

The following sample procedures are provided to further clarify the difference between hiding modules in Microsoft Excel 5.0, 7.0, and 97.

   Sub HideMe()
       ThisWorkbook.Modules("Module1").Visible = False
   End Sub

   Sub ShowMe()
       ThisWorkbook.Modules("Module1").Visible = True
   End Sub

   Sub ReallyHideModule2()
       ThisWorkbook.Modules("Module2").Visible = xlVeryHidden
   End Sub

Microsoft Excel 5.0 and 7.0:

When you run the HideMe procedure, Microsoft Excel hides Module1. Running the ShowMe procedure unhides Module1. Running the ReallyHideModule2 procedure hides Module2 and prevents it from being unhidden without using a macro or code.

Microsoft Excel 97:

Nothing happens when you run these sample procedures in Microsoft Excel 97. Because modules are not tabbed sheets, they no longer have a Visible property, and you cannot hide or unhide them.

Similarly, using the Protect or Unprotect methods to protect or unprotect a module does not work in Microsoft Excel 97. Because modules are not tabbed sheets, you cannot protect or unprotect them.


Additional query words: XL97 addin 8.0 WD97 PP97
Keywords : kbcode xlui xladdins xl97vbmigrate
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb
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: February 27, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.