目录

Commit 方法

优质
小牛编辑
132浏览
2023-12-01

将指定 SignatureSet 集合的所有更改提交到磁盘。直到执行 Commit 方法,SignatureSet 集合的更改才进行保存。

expression.Commit

expression 必需。该表达式返回“应用于”列表中的对象之一。

示例

本示例提示用户选择 Microsoft Word 中活动文档的数字签名。要使用本示例,请在 Word 中打开文档并调用该函数。该函数将进行测试以确保用户所选择的数字签名在 12 个月内不会过期。如果将会过期,则不附加证书。

Function AddSignature() As Boolean

    On Error GoTo Error_Handler

    Dim sig As Signature

    'Display the dialog box that lets the
    'user select a digital signature.
    'If the user selects a signature, then
    'it is added to the Signatures
    'collection. If the user doesn't, then
    'an error is returned.
    Set sig = ActiveDocument.Signatures.Add

    'Test to make sure that the new Signature object
    'doesn't expire too soon. This expression calculates
    'the number of months until the Signature object expires.
    If DateDiff("m", sig.SignDate, sig.ExpireDate) < 12 Then

        MsgBox "This certificate will expire in less than 1 year." & vbCrLf & _
        "Please use a newer certificate."

        AddSignature = False
        sig.Delete
    Else
        AddSignature = True
    End If

    'Commit all signatures in the SignatureSet collection to the disk.
    ActiveDocument.Signatures.Commit

    Exit Function
Error_Handler:
    AddSignature = False
    MsgBox "Action cancelled."
End Function