简体   繁体   English

VBA Userform用户签名输入到电子表格

[英]VBA Userform user signature input into spreadsheet

I'm new to InkPicture but I like to use it for user to put signature into the form. 我是InkPicture的新手,但我喜欢使用它供用户将签名放入表单中。

I can't seem to save the signature (inkpicture) to the spreadsheet it just inputs it as 0 into the cell I specify. 我似乎无法将签名(inkpicture)保存到电子表格,它只是将签名输入为0到我指定的单元格中。

With UserForm1.InkPicture1.InkEnabled = False Set.Ink Me.InkPicture1.Ink .InkEnabled = True 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 With UserForm1.InkPicture1.InkEnabled = False Set.Ink Me.InkPicture1.Ink .InkEnabled = True 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. 谢谢。

This is not a complete answer but will help you on your way, comment if you have any questions. 这不是一个完整的答案,但会帮助您,如有任何疑问请发表评论。

First you will have to have a text box on your form that requires the asset ID, this will have to be amended to match your current form. 首先,您必须在表单上有一个要求输入资产ID的文本框,该文本框必须进行修改以匹配您当前的表单。

Dim RowN As Long
Dim SearchTxt
SearchTxt = TextBox1.Value 'This should be set to the text box name on the form of the  asset ID
    On Error Resume Next
    RowN = Application.WorksheetFunction.Match(SearchTxt, Range("A:A"), 0)
    On Error GoTo 0
    If RowN > 0 Then

            'your code here if matches
            MsgBox RowN ' display the row number

        Else

            'your code here if no match, possibly add new row of data
            MsgBox "No match found" 
End If

Now you can amend each line of code to use the found row number, for example: 现在,您可以修改每行代码以使用找到的行号,例如:

Sheets("Data").Cells("A" & RowN).Value = TextBox1.Txt

If I was creating this form, I would add a search button to check the asset ID and where it finds a match, all the text boxes would then be populated with the current values of the data, these can then be amended before adding back to the sheet. 如果我正在创建此表单,则将添加一个搜索按钮以检查资产ID,并在其中找到匹配项,然后将使用数据的当前值填充所有文本框,然后可以对其进行修改,然后再添加到工作表。

The following will look for the ID in Column A and if found will use that row to enter the data, this assumes that the ID is stored in TextBox1.Text, amend as required: 以下内容将在A列中查找ID,如果找到该ID将使用该行输入数据,则假定该ID存储在TextBox1.Text中,并根据需要进行修改:

Private Sub SB1_Click()

Dim lrREG As Long, lrB As Long, lrDep As Long, lrDis As Long, lrDAT As Long
Dim foundID As Range


        Set foundID = Sheets("Data").Range("A:A").Find(What:=TextBox1.Text, Lookat:=xlWhole)
        If Not foundID Is Nothing Then
            Sheets("Data").Cells(foundID.Row, "A").Value = TextBox1.Text
            Sheets("Data").Cells(foundID.Row, "B").Value = TextBox2.Text
            Sheets("Data").Cells(foundID.Row, "C").Value = TextBox3.Text
        Else
            lrDAT = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row + 1
            Sheets("Data").Cells(lrDAT, "A").Value = TextBox1.Text
            Sheets("Data").Cells(lrDAT, "B").Value = TextBox2.Text
            Sheets("Data").Cells(lrDAT, "C").Value = TextBox3.Text
        End If

    lrREG = Sheets("Register").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Register").Cells(lrREG + 1, "A").Value = TextBox1.Text
    Sheets("Register").Cells(lrREG + 1, "B").Value = TextBox2.Text
    Sheets("Register").Cells(lrREG + 1, "C").Value = TextBox3.Text

    lrB = Sheets("Built").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Built").Cells(lrB + 1, "A").Value = TB1.Text
    Sheets("Built").Cells(lrB + 1, "B").Value = TB2.Text
    Sheets("Built").Cells(lrB + 1, "C").Value = TB3.Text
    Sheets("Built").Cells(lrB + 1, "D").Value = TB4.Text
    Sheets("Built").Cells(lrB + 1, "E").Value = TB5.Text
    Sheets("Built").Cells(lrB + 1, "F").Value = TB6.Text

    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, "E").Value = TBox5.Text
    Sheets("Deploy").Cells(lrDep + 1, "F").Value = TBox6.Text

    lrDis = Sheets("Dispose").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Dispose").Cells(lrB + 1, "A").Value = TextBo1.Text
    Sheets("Dispose").Cells(lrDis + 1, "B").Value = TextBo2.Text
    Sheets("Dispose").Cells(lrDis + 1, "C").Value = TextBo3.Text
    Sheets("Dispose").Cells(lrDis + 1, "D").Value = TextBo4.Text
    Sheets("Dispose").Cells(lrDis + 1, "E").Value = TextBo5.Text
    Sheets("Dispose").Cells(lrDis + 1, "F").Value = TextBo6.Text
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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