vba - 如何使用Excel的墨迹工具添加手写签名?

标签 vba excel

我想在我公司的一些表单中添加手写数字签名。

目标是选择一个文档,添加签名(通过使用绘图板,可以使用 Excel 的墨迹工具完成)并将文件作为 PDF 存储在服务器中。这将消除打印然后扫描表格以获得签名的必要性。

我使用 Excel 作为文件操作和搜索的主界面。我没有找到任何通过 VBA 使用 Excel - Ink 工具的引用资料/库。

如何在 VBA 中启动 Ink Tools 对象?我是否必须使用不同的软件来获取签名?

最佳答案

更新:

在 @Macro Man 为我指出正确的方向后,我发现了一些有助于启动和运行电子签名的 Material 。

我在 MSDN 上找到了一些 Material Digital Ink Signatures - Concepts and Technologies InkPicture Class 通过 PictureBox/Userform 谈论 VB.net 和 C# 上的 Ink 集合,这与另一个 Stackoverflow response 中的 InkEdit 控件相结合。其中我意识到 VBA 工具箱有一个 InkPicture Control 附加控件,可用于通过用户表单收集手写电子签名。

请逐步查看以下内容:

在“工具”>“其他控件”下的附加控件上的 VBA 工具箱中,有一个 InkPicture 控件,它允许您创建签名用户表单。

enter image description here

添加后,InkPicture 可用作工具箱上的任何其他控件。

enter image description here

然后是为签名请求初始化用户表单的情况。我使用的是绘图板,但其他硬件也应该可以工作。

enter image description here

并根据需要存储或使用生成的图像,在我的例子中,在服务器中保存临时版本,然后调整大小并添加到 Word 文档。

<小时/>

编辑:

here 中回答类似问题后,关于如何使用 Userform InkPicture 将图像签名输入工作表/特定单元格,我想我应该为那些感兴趣的人编辑这个答案。

下面的代码将允许您打开用户表单,以便用户可以在墨迹字段上签名、临时保存图像、将 InkPicture 添加到工作表中并删除临时图像。

设置您的用户表单(我的设置是这样的,有几个额外的选项),用户表单名为Signature_pad,您需要的基本选项是Private Sub Use_Click().

enter image description here

这是用户表单内的代码:

Private Sub Use_Click()
    
    'dim object type and byte array to save from binary
    Dim objInk As MSINKAUTLib.InkPicture
    Dim bytArr() As Byte
    Dim File1 As String
    
    'get temp file path as $user\Temp\[file name]
    FilePath = Environ$("temp") & "\" & "Signature.png"
    
    ' set objInk as image/strokes of InkPicture control form object
    Set objInk = Me.SignPicture
    
    'if object is not empty
    If objInk.Ink.Strokes.Count > 0 Then
        'get bytes from object save
        bytArr = objInk.Ink.Save(2)
        'create file for output
        Open FilePath For Binary As #1
        'output/write bytArr into #1/created (empty)file
        Put #1, , bytArr
        Close #1
    End If
    
    'set public File as file path to be used later on main sub
    Signature.File = FilePath

    Unload Me
End Sub

Private Sub Cancel_Click()
    End
End Sub

Private Sub ClearPad_Click()
    'delete strokes/lines of signature
    Me.SignPicture.Ink.DeleteStrokes
    'refresh form
    Me.Repaint
End Sub

下面是调用用户表单并处理签名的Main sub(名为Signature的模块),您可以使用按钮或形成另一个

'public temp file path
Public File
Sub collect_signature()

    'Dim and call userform
    Dim myUserForm As Signature_pad

    Set myUserForm = New Signature_pad
    myUserForm.Show
    Set myUserForm = Nothing
    
    'insert image/signature from temp file into application active sheet
    Set SignatureImage = Application.ActiveSheet.Shapes.AddPicture(File, False, True, 1, 1, 1, 1)
    
    'scale image/signature
    SignatureImage.ScaleHeight 1, True
    SignatureImage.ScaleWidth 1, True
    
    'image/signature position
    SignatureImage.Top = Range("A1").Top
    SignatureImage.Left = Range("A1").Left
    
    'delete temp file
    Kill File

End Sub

请务必重命名用户表单名称按钮名称或代码以匹配按钮的名称。

关于vba - 如何使用Excel的墨迹工具添加手写签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37164849/

相关文章:

excel - 如何将 Power Query 表保存为新工作簿中的常规表(无连接)?

vba - 查找包含公式的单元格区域中最后一个非空行

vba - Outlook 2010 规则 : Move message if greater than 5 recipients

excel - 使用 AND() 函数进行条件格式化

excel - 如何使用 EPPlus 将电子表格单元格的内容设置为会计格式?

excel - 查找并替换文件夹中所有 Excel 文件中的字符串

excel - 源代码属性 VB_VarMemberFlags 在 VBA 中起什么作用(如果有的话)?

VBA:新集合 -> 模块不是有效类型

excel - 如何每隔一分钟保存一个 Excel 文件?

vba - Excel VBA 选择包含文本字符串的单元格,然后将这些单元格复制并粘贴到新工作簿中