Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
XL2000: How to Help Protect Visual Basic Code in Excel
Article ID: 213903 - View products that this article applies to.
This article was previously published under Q213903
In Microsoft Excel 2000, unlike versions earlier than Excel 97, you cannot hide Microsoft Visual Basic for Applications modules. If you want to prevent users from seeing the Visual Basic code, you can lock the code in the workbook and thereby prevent users from viewing it. However, if you save the workbook as either an Excel 5.0/95 workbook or an Excel 97-2000 and 5.0/95 workbook, the module protection is lost when you open the workbook in Excel 5.0 or 7.0. Therefore, to use this method, you must maintain separate versions of the workbook for users of Excel 97 or 2000 and users of Excel 5.0 or 7.0.
This article describes a method of protecting Visual Basic code while allowing users of different versions of Excel to use the same version of your program. This method requires that you create the program in Excel 5.0 or 7.0 and then save it as an add-in file. This method hides the code in all versions of Excel. Any add-in code that you create in Excel 5.0 or 7.0 is not visible when the file is opened in Excel 2000.
In the example in this article, you compile a program into an add-in file. The interface for the program consists of two worksheets, which are copied into a new workbook when the add-in file is opened.
Note To create an add-in that is compatible with Excel 5.0 or 7.0 and Excel 97 or 2000, use the earliest version of Excel in which the add-in will be used. For example, if the workbook will be used with Excel 7.0 and Excel 2000, create the add-in in Excel 7.0.
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 a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
Microsoft Certified Partners - https://partner.microsoft.com/global/30000104
Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
Creating the Source Workbook File for the Add-InTo create the workbook, follow these steps:
Creating the Add-In FileTo create the add-in file, follow these steps:
For more information about how to insert an add-in, click Microsoft Excel Help on the Help menu, type load an installed add-in program in microsoft excel in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/212536/EN-US/ )OFF2000: How to Run Sample Code from Knowledge Base Articles