Office 2000
You can lock the VBA project contained within a document, template, or database. For Outlook, you can lock the VBA project for the local session of Outlook, which is stored in the VbaProject.OTM file. Similarly, for FrontPage, you can lock the VBA project for the local session of FrontPage, which is stored in the Microsoft FrontPage.fpm file. You can lock only an entire VBA project, not individual components within the project. This means that when you lock a VBA project, you are controlling access to all standard modules (including the default ThisDocument, ThisWorkbook, and ThisOutlookSession modules for Word, Excel, and Outlook, respectively), all class modules, and all UserForms contained by the project.
Important VBA
project passwords are case-sensitive. To view a locked VBA project, you
must use the exact case you used when setting the password. If you lose
or forget the password, there is no way to view the locked VBA project.
When password-protecting a VBA project, be sure to write down the
password and keep it in a physically secured location.
To lock a VBA project for viewing
-
Open the document, template, or database that contains the VBA project
you want to protect. For Outlook or FrontPage, start Outlook or
FrontPage on the computer that contains the VBA project you want to
protect.
-
Open the Visual Basic Editor.
-
In the Project Explorer, right-click the project you want to protect, and then click ProjectName Properties on the shortcut menu.
- On the Protection tab, select the Lock project for viewing check box, enter and confirm the password, and then click OK.
Important You can set a password without selecting the Lock project for viewing check box, but doing so only controls access to the Project Properties dialog box itself. If you set a password without selecting the Lock project for viewing check box, users will be able to view and modify your code.
There is no way to programmatically specify a password for a locked VBA
project. If you write code that attempts to work with components in a
locked VBA project, the Visual Basic Editor will display a dialog box to
prompt the user for the correct password. If the user specifies the
correct password, your code will continue to run. If the user doesn't
specify the correct password, a trappable error will be returned.To determine if a VBA project is locked, set a reference to the Microsoft Visual Basic for Applications Extensibility 5.3 object library, and then inspect the Protection property of the VBA project. The following example shows how to check the Protection property of the VBA project in a Word document.
Function IsWordProjectLocked(strDocPath As String) As Boolean
Dim vbpProj As VBIDE.VBProject
Dim docProj As Word.Document
' Open document.
Set docProj = Documents.Open(strDocPath)
' Set reference to document's VBA project.
Set vbpProj = docProj.VBProject
' Check Protection property of VBA project.
If vbpProj.Protection = vbext_pp_locked Then
IsWordProjectLocked = True
Else
IsWordProjectLocked = False
End If
End Sub
The IsWordProjectLocked procedure is available in the IsProjectLocked
module in CheckProject.dot in the ODETools\V9\Samples\OPG\Samples\CH17
subfolder on the Office 2000 Developer CD-ROM.
No comments:
Post a Comment