Modifying code hat inserts Digital Signature BLock into PDF Output form Excel using VBA

Status
Not open for further replies.

chipsworld

Board Regular
Joined
May 23, 2019
Messages
161
Office Version
  1. 365
Hi all,
I tried to ask from the original post by John_w, but am guessing that no one is watching that so...here goes.

This code was originally posted by John_w back in 2019, and works beautifully, but had modification questions...

How could this be modified to allow for two (or more) signature blocks to be placed on the same PDF Form?

I have been playing with it, but having no luck so far...

Any input would be very welcome...

VBA Code:
Public Sub Save_Sheet_As_PDF_Add_Signature_Field()

Worksheets("Calc Sheet").Unprotect Password:=""

    Dim PDDoc As Object
Dim AVDoc As Object
Dim JSO As Object
Dim formField As Object
Dim formField2 As Object
Dim inputPDFfile As String, outputPDFfile As String
Dim coords() As Variant
Dim coords2() As Variant
    Dim filnam As String

    filnam = Worksheets("Formulas").Range("V5") & " - " & Worksheets("Formulas").Range("V4") & " - " & Format(Date, "dd MMM yy")
' coordinates for QC signature
Const BOTTOM_LEFT_X = 315
Const BOTTOM_LEFT_Y = 50
Const WIDTH = 320
Const HEIGHT = 30


'Coordinates specifying position and size of the signature field's bounding rectangle, with origin (0,0) at bottom left of page,
'in the following order: top-left x, top-left y, bottom-right x and bottom-right y.

coords = Array(BOTTOM_LEFT_X, BOTTOM_LEFT_Y + HEIGHT, BOTTOM_LEFT_X + WIDTH, BOTTOM_LEFT_Y)
   

    With ActiveSheet
inputPDFfile = ThisWorkbook.Path & "\Calc Sheets\delete\" & filnam & ".pdf"
outputPDFfile = ThisWorkbook.Path & "\Calc Sheets\" & filnam & " - " & " WSF.pdf"
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=inputPDFfile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    End With

    Set PDDoc = CreateObject("AcroExch.PDDoc")
Set AVDoc = CreateObject("AcroExch.AVDoc")

If PDDoc.Open(inputPDFfile) Then
Set JSO = PDDoc.GetJSObject
Set formField = JSO.AddField("SignatureField", "signature", 0, coords) '0 = 1st page
        formField.StrokeColor = JSO.Color.Black  'StrokeColor sets the border and text colours of the field

        If PDDoc.Save(1, outputPDFfile) Then
PDDoc.Close
AVDoc.Open outputPDFfile, vbNullString
AVDoc.BringToFront
AVDoc.Close True
Else
MsgBox "Unable to save: " & outputPDFfile
End If
End If

Kill inputPDFfile

Worksheets("Calc Sheet").Protect Password:=""
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Status
Not open for further replies.

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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