Microsoft Office 2000/Visual Basic Programmer's Guide |
Signing a VBA project does not prevent you from running code or working with objects contained in that project from Automation (formerly known as OLE Automation) code. The warnings and dialog boxes that are displayed to users when they open signed documents from an Office 2000 application's user interface are disabled when a signed document is opened and worked with from code.
However, if you use code to add or change code in a signed document, those modifications will invalidate the digital signature and cause the document to be flagged as suspect the next time it is opened from an Office 2000 application's user interface. There is no way to prevent modifications to the project from invalidating the signature (doing so would create a security hole), but you can detect the presence of a signature, so that you can display a message that allows the user to choose whether to continue. This message should also inform the user that if he or she continues, the document must be re-signed before it can be trusted. Similarly, you may want to use VBA to scan a set of documents to determine if their VBA projects haven't been signed before distributing them.
To detect the presence of a digital signature in Word, Excel, and PowerPoint, check the VBASigned property of the corresponding document object. For example, to reference the VBASigned property, use a line of code in this form
object.VBASigned
where object is a reference to a Document object (Word), a Workbook object (Excel) or a Presentation object (PowerPoint). If the VBASigned property is True, the VBA project associated with the document is digitally signed; if the VBASigned property is False, the document hasn't been signed. The following procedure detects a digital signature in a Word document by checking the value of the VBASigned property of the document:
Public Function IsWordProjectSigned(strDocPath As String) As Boolean
Dim docProj As Word.Document
' Open document.
Set docProj = Documents.Open(strDocPath)
' Check VBASigned property of document.
If docProj.VBASigned Then
IsWordProjectSigned = True
Else
IsWordProjectSigned = False
End If
End Function
The IsWordProjectSigned procedure is available in the IsProjectSigned module in CheckProject.dot in the ODETools\V9\Samples\OPG\Samples\CH17 subfolder on the Office 2000 Developer CD-ROM.