简体   繁体   中英

Userform VBA InkPicture input into sheet (specific cell) as image user signature

I'm new to InkPicture but I like to use it for user to put signature into the form.

I can't seem to save the signature (inkpicture) to the spreadsheet it just inputs it as 0 into the cell I specify.

With UserForm1.InkPicture1.Picture = InkPicture1.Picture


End With

lrDep = Sheets("Deploy").Range("A" & Rows.Count).End(xlUp).Row 
Sheets("Deploy").Cells(lrDep + 1, "A").Value = TBox1.Text 
Sheets("Deploy").Cells(lrDep + 1, "B").Value = TBox2.Text 
Sheets("Deploy").Cells(lrDep + 1, "C").Value = TBox3.Text 
Sheets("Deploy").Cells(lrDep + 1, "D").Value = TBox4.Text 
Sheets("Deploy").Cells(lrDep + 1, "G").Value = InkPicture1.Ink 

Could someone please help me. Thank you.

I when through something similar some time ago.

You can see my question here .

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 objInk As MSINKAUTLib.InkPicture
    Dim bytArr() As Byte
    Dim File1 As String

    FilePath = Environ$("temp") & "\" & "Signature.png"

    Set objInk = Me.SignPicture

    If objInk.Ink.Strokes.Count > 0 Then
        bytArr = objInk.Ink.Save(2)
        Open FilePath For Binary As #1
        Put #1, , bytArr
        Close #1
    End If

    Signature.File = FilePath

    Unload Me
End Sub
Private Sub Cancel_Click()
    End
End Sub
Private Sub ClearPad_Click()
    Me.SignPicture.Ink.DeleteStrokes
    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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM