Ink Tools - VBA - Excel Digital Signature/Drawing

萝らか妹 提交于 2020-01-03 15:24:08

问题


I wanted to add a handwritten digital signature in some of my companies forms. The goal is pretty straight forward, select a document, add a signature (through the use of a drawing pad, which can be done with Excel's Ink Tools) and store the file in the server as PDF. This would cut out the necessity of printing and then scanning the form back in just to obtain a signature.

I'm using excel for the main interface for file manipulation and search,but unfortunately I've not been able to find any references/libraries for the use of Excel - Ink Tools through VBA.

Could you guys please point me in the right direction to find some references or a simple snippet on how to start Ink Tools Objects in VBA? or would I have to use a different software to get the signature?

Thank in Advance.

Miguel

Edited my own Answer with an update on how use Userform to insert signature image in Excel


回答1:


Is it the InkEdit Control you're after?

This is one of the standard libraries that you can find in Tools->References




回答2:


Update:

Hi Guys,

After @Macro Man pointed me in the right direction I found some material that helped get the eSignature up and running.

I've found some material on MSDN Digital Ink Signatures - Concepts and Technologies and InkPicture Class that talk about the Ink collection on VB.net and C# through a PictureBox/Userform , this coupled with the InkEdit Control in another Stackoverflow response in which I realised that VBAs tool box had a InkPicture Control additional control that could be utilized to collect the handwritten eSignature through User form.

Please find below step by step:

In VBAs toolbox on additional control under Tools > Additional Controls there is the InkPicture Control which allows you to create a signature Userform.

Once Added InkPicture can be used as any other control on the toolbox.

Then its a case of initialising the UserForm for the Signature request. I'm using a drawing pad, but other hardware should work as well.

And storing or utilising the resultant image at need, in my case saving a temp version in the server to then resize and add to a Word document.


Edit:

After answering a similar question in here, on how to use Userform InkPicture to input image signature into a worksheet/specific cell, I thought I'd edit this answer for those interested.

The below code will allow you to, open the userform so the user can sign the ink field, save the image temperately, add the InkPicture to your worksheet and kill the temp image.

Set up your UserForm (mine is set up like this, with a couple extra options) the UserForm is named Signature_pad, the essential option you need is Private Sub Use_Click().

This is the code inside the Userform:

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

Below is the Main sub (Module called Signature) to call the userform and handle the signature, you can call this Sub with a button or form another Sub.

'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

Be sure to rename either the Userform Name and Buttons Name Or the code to match the names of you buttons.



来源:https://stackoverflow.com/questions/37164849/ink-tools-vba-excel-digital-signature-drawing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!