Userform VBA InkPicture输入到工作表(特定单元格)作为图像用户签名 [英] Userform VBA InkPicture input into sheet (specific cell) as image user signature

查看:569
本文介绍了Userform VBA InkPicture输入到工作表(特定单元格)作为图像用户签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是InkPicture的新手,但我喜欢用它来让用户将签名放入表单中。



我似乎无法将签名(inkpicture)保存到电子表格中,只是将其输入为我指定的单元格中的0。

 使用UserForm1.InkPicture1.Picture = InkPicture1.Picture 


结束时

lrDep =表格(部署)。范围(A和Rows.Count).End(xlUp)。行
表格(部署)。单元格(lrDep + 1,A)。值= 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)。值= InkPicture1.Ink

有人可以帮助我。
谢谢。

解决方案

我在前段时间通过类似的东西。



您可以在



这是Userform中的代码:

  Private Sub Use_Click()

Dim objInk As MSINKA UTLib.InkPicture
Dim bytArr()As Byte
Dim File1 As String

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

设置objInk = Me.SignPicture

如果objInk.Ink.Strokes.Count> 0然后
bytArr = objInk.Ink.Save(2)
打开FilePath for Binary作为#1
Put#1 ,, bytArr
关闭#1
结束If

Signature.File = FilePath

卸载我
结束Sub
Private Sub Cancel_Click()
End
End Sub
Private Sub ClearPad_Click()
Me.SignPicture.Ink.DeleteStrokes
Me.Repaint
End Sub

以下是主要子(模块名为签名)来调用userform和处理签名,你可以用按钮调用这个 Sub 或者形成另一个 Sub

 '公共临时文件路径
公共文件
Sub collect_signature()

'昏暗并调用userform
Dim myUserForm As Signature_pad

设置myUserForm = New Signature_pad
myUserForm.Show
设置myUserForm = Nothing

'将临时文件中的图像/签名插入应用程序活动表
设置SignatureImage = Application.ActiveSheet.Shapes.AddPicture(File,False,True,1,1,1,1)

'比例图像/签名
SignatureImage.ScaleHeight 1,True
SignatureImage.ScaleWidth 1,True

'图像/签名位置
SignatureImage.Top = Range( A1)。顶部
SignatureImage.Left =范围(A1)。左

'删除临时文件
杀死文件

结束子

请务必重命名 Userform Name 按钮名称或与您按钮的名称匹配的代码


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.

这篇关于Userform VBA InkPicture输入到工作表(特定单元格)作为图像用户签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆