我只是在学习使用 CoSign SAPI。我下载了 Visual Studio 的示例 VB.Net 程序代码,它运行正常。然后我尝试在 Microsoft Word 2010 中将代码作为 VBA 模块运行。代码在 SAPI.logon 语句之前执行正常并失败。下面是我正在使用的代码。另外,您知道在 Word VBA 中使用 SAPICom 的任何其他示例程序吗?非常感谢您的帮助。
公共子 testCoSign()
Const SAPI_OK As Integer = 0
Dim rc As Integer
Dim SAPI As New SAPICrypt
Dim sesMyHandle As New sesHandle
'Custom Values
Dim filePath As String 'PDF file to sign
Dim username As String 'CoSign account username
Dim password As String 'CoSign account password
Dim domain As String 'CoSign account domain
Dim sigPageNum As Integer 'Create signature on the first page
Dim sigX As Integer 'Signature field X location
Dim sigY As Integer 'Signature field Y location
Dim sigWidth As Integer 'Signature field width
Dim sigHeight As Integer 'Signature field height
Dim timeFormat As String 'Time appearance format mask
Dim dateFormat As String 'Date appearance format mask
Dim appearanceMask As Integer 'Elements to display on the signature field
'Initialize variables
Set sesMyHandle = Nothing
filePath = "c:\\temp\\demo.doc"
username = "JSMITH"
password = "*******"
sigPageNum = 1
sigX = 145
sigY = 125
sigWidth = 160
sigHeight = 45
timeFormat = "hh:mm:ss"
dateFormat = "dd/MM/yyyy"
appearanceMask = SAPI_ENUM_DRAWING_ELEMENT.SAPI_ENUM_DRAWING_ELEMENT_GRAPHICAL_IMAGE Or _
SAPI_ENUM_DRAWING_ELEMENT.SAPI_ENUM_DRAWING_ELEMENT_SIGNED_BY Or _
SAPI_ENUM_DRAWING_ELEMENT.SAPI_ENUM_DRAWING_ELEMENT_TIME
' Initialize SAPI library
rc = SAPI.Init
If rc <> SAPI_OK Then
MsgBox "error initializing SAPI", vbOKOnly, "Error"
End If
' Acquire SAPI session handle
rc = SAPI.HandleAcquire(sesMyHandle)
If rc <> SAPI_OK Then
MsgBox "error acquiring SAPI session handle", vbOKOnly, "Error"
End If
' Personalize SAPI Session
rc = SAPI.Logon(sesMyHandle, username, "", password)
If rc <> SAPI_OK Then
MsgBox "failure to authenticate user", vbOKOnly, "Error"
End If
结束子