Public Sub AddDigSig()
'Declare the object and data type that will be used.
Dim bAddSig As Boolean
Dim sig As Signature
Dim wordapp As Word.Application
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
Set sig = ActiveDocument.Signatures.Add
'Check the validity of the digital certificate used for signing.
'If it hasn't expired AND not revoked, then set bAddSig to True.
If sig.IsCertificateExpired = False And _
sig.IsCertificateRevoked = False Then
bAddSig = True
Else
'If it isn't valid, delete the signature on the document.
sig.Delete
bAddSig = False
End If
'Commit the signature. Until the Commit method is executed,
'none of the changes to the SignatureSet collection are saved.
ActiveDocument.Signatures.Commit
'Clean up by destroying the sig object now that it isn't needed anymore.
Set sig = Nothing
'wordApp.Documents.Close ("c:\word\hola.doc")
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "Document signing action has been cancelled."
Set sig = Nothing
wordapp.Quit
Set wordapp = Nothing
End Sub
Public Sub DigSigValid()
'Declare the objects and data type that will be used.
Dim sSigValid As String
Dim objSignature As Signature
Dim wordapp As Word.Application
'When there is an error, go to Error_Handler for error handling.
On Error GoTo Error_Handler
'Check all of the signatures
sSigValid = ""
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open ("c:\word\hola.doc")
wordapp.Visible = True
For Each objSignature In ActiveDocument.Signatures
sSigValid = sSigValid + "Is Signature from: " + objSignature.Signer _
+ " Valid?: " + Str$(objSignature.IsValid) + vbCrLf
Next objSignature
MsgBox (sSigValid)
Set objSignature = Nothing
wordapp.Quit
Set wordapp = Nothing
Exit Sub
Error_Handler:
MsgBox "An error has occurred while trying to validate the digital signature. Please try running the DigSigValid macro again."
Set objSignature = Nothing
wordapp.Quit
Set wordapp = Nothing
End Sub