I am looking to print pdf files with vba but want to add a text box with information that changes based on a list in excel. I have three columns in the excel file with information such as file location for the material pdf, number of copies and the order number that it needs to run on.
Currently I have to hand write all order numbers on the papers after my vba prints the pdf files. Is there a way to add lines of code to my code that will add a text box or watermark that will have the order number on each pdf. Order number can change based on the pdf file being rpinted. Thank you! Code below:
Sub Button4_Click()
Dim Msg As String, Ans As Variant
Msg = "Would you like to print all of the BOMs"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
'NOTE:
'/s=don't show splash screen
'/n=new instance
'/h=minimized window
'/t=print to default printer; or use /t <filename> <printername> <drivername> <portname>
'CHECK YOUR ADOBE READER VERSION, AND USE CORRECT PATH..
zProg = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
zLastRow = [M65536].End(xlUp).Row 'find last row in column [M]; e.g. 15
temp = "M1:M" & zLastRow 'e.g. "M1:M15"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For Each cell In Range(temp) 'loop through all entries in range
zFile = cell.Value 'fetch filename from cell
r = cell.Row
zPrintCopies = Cells(r, "N")
If zPrintCopies = "" Then
zPrintCopies = 1
Cells(r, "B") = 1
End If
If zFile Like "*.pdf" Then 'check it is a pdf file type
.LeftHeader = Format(Now(), "dd/mm/yy")
For i = 1 To zPrintCopies
Shell (zProg & " /n /h /t " & zFile) 'execute command to print the pdf document
Next i
End If 'end of test for pdf file type
Next 'process next file in list
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub