Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add handwritten signature using Excel's Ink Tools?

Tags:

excel

vba

I want to add a handwritten digital signature to some of my company's forms.

The goal is to, 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 to obtain a signature.

I'm using Excel for the main interface for file manipulation and search. I've not found any references/libraries for the use of Excel - Ink Tools through VBA.

How do I start Ink Tools Objects in VBA? Would I have to use a different software to get the signature?

like image 749
Miguel_Ryu Avatar asked May 11 '16 13:05

Miguel_Ryu


1 Answers

Update:

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.

enter image description here

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

enter image description here

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.

enter image description here

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().

enter image description here

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.

like image 100
Miguel_Ryu Avatar answered Oct 14 '22 02:10

Miguel_Ryu