VBA code to place default signature in excel sheet

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
Hello,

Is it possible to add a default excel signature with VBA? I would like to add a default signature (maybe excel asking to enter the password) when pressing Button1 to an excel sheet. This sheet will be later on be converted to a pdf file using VBA.

Thank you.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
VBA Code:
Sub InsertSignature()
    Dim pic As String, cel As Range, shp As Shape, msg As String
    If InputBox("Signature Password", "Enter Password") = "PassWord123" Then
        pic = "C:\folder\subfolder\DefaultSignature.jpg"
        Set cel = Range("A30")
        On Error Resume Next
        Set shp = ActiveSheet.Shapes.AddPicture(pic, msoFalse, msoCTrue, cel.Left, cel.Top, 150, 50)
        If Err.Number <> 0 Then msg = "Signature plate stolen"
    Else
        msg = "Signature declined - incorrect password"
    End If
On Error GoTo 0
If msg <> "" Then MsgBox msg, vbExclamation, "oops"
End Sub
 
Upvote 0
Hi, thank you for your reply on this. I think I missed your message before, but now I just tried the code you shared and it works. I was wondering, can the pic be deleted? This because I have a code that fills an excel sheet every time a new entry is created. When the entry is closed, the picture will need to be placed on the excel, but the form needs to be clear out for the next entry. Is this possible?
 
Upvote 0
The easiest way is to name the picture in the original procedure
Rich (BB code):
Sub InsertSignature()
    Dim pic As String, cel As Range, shp As Shape, msg As String    
    If InputBox("Signature Password", "Enter Password") = "PassWord123" Then
        pic = "C:\folder\subfolder\DefaultSignature.jpg"
        Set cel = Range("A30")
        On Error Resume Next
        Set shp = ActiveSheet.Shapes.AddPicture(pic, msoFalse, msoCTrue, cel.Left, cel.Top, 150, 50)
        shp.Name = "SignaturePlate"
        If Err.Number <> 0 Then msg = "Signature plate stolen"
    Else
        msg = "Signature declined - incorrect password"
    End If
On Error GoTo 0
If msg <> "" Then MsgBox msg, vbExclamation, "oops"
End Sub

so that it can be deleted like this
Rich (BB code):
Sub RemoveSignature()
    On Error Resume Next
    ActiveSheet.Shapes("SignaturePlate").Delete
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,732
Messages
6,126,540
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top