Forum Discussion
bazianm
Apr 03, 2025Copper Contributor
Word Mail Merge->PDF->Auto Name
I am trying to think of a way to automate a process. Part of this is in word and part with Adobe. Basically, here is the scenario. Every year all the staff in the company (about 350-400 employees) ge...
Kidd_Ip
Apr 04, 2025MVP
Take this:
- Mail Merge in Word
Use Microsoft Word's mail merge feature to create individual documents:
- Data Source: Use your employee spreadsheet as the source.
- Mail Merge Setup: Link the spreadsheet to your employment agreement template in Word and generate the merged documents for all employees.
- VBA for Automation: Automate the merge process and save each document with the employee's name:
Sub MailMergeAndSave()
Dim wdDoc As Document
Dim wdMergeDoc As Document
Dim employeeName As String
Set wdDoc = Documents.Open("YourTemplatePath")
With wdDoc.MailMerge
.OpenDataSource Name:="YourSpreadsheetPath"
.Destination = wdSendToNewDocument
.Execute
End With
For Each wdMergeDoc In Application.Documents
employeeName = wdMergeDoc.MailMerge.DataSource.DataFields("EmployeeName").Value
wdMergeDoc.SaveAs2 "C:\Path\" & employeeName & ".docx"
wdMergeDoc.Close
Next wdMergeDoc
wdDoc.Close
End Sub
- Convert to PDF
Automate Word to convert the saved Word documents into PDF format:
- Use VBA or a Python library like win32com to handle this step.
- Python Example (with win32com):
import os
import win32com.client
word = win32com.client.Dispatch("Word.Application")
word.Visible = False
input_folder = "C:\\Path\\"
output_folder = "C:\\Path\\PDFs\\"
for filename in os.listdir(input_folder):
if filename.endswith(".docx"):
doc_path = os.path.join(input_folder, filename)
pdf_path = os.path.join(output_folder, filename.replace(".docx", ".pdf"))
doc = word.Documents.Open(doc_path)
doc.SaveAs(pdf_path, FileFormat=17) # 17 is the PDF format code
doc.Close()
word.Quit()
- Automate Digital Signature Requests
Use Adobe's API or Acrobat Actions to request digital signatures:
- Adobe Acrobat API: Use the Adobe Sign API to send documents for digital signatures programmatically.
- Python (with Adobe API): Install the required libraries and authenticate to use Adobe's services for document distribution.
- Email Automation
Send the signed PDF files via email:
- Use Python's smtplib or an email library like yagmail to automate the email process.
- Sample:
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders
sender_email = "email address removed for privacy reasons"
sender_password = "your_password"
with open("C:\\Path\\employee_list.csv", "r") as file: # Replace with your spreadsheet reader
for line in file:
employee_email, pdf_path = line.strip().split(",") # Customize for your data structure
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = employee_email
message["Subject"] = "Your Employment Contract"
body = "Dear Employee,\n\nPlease find attached your employment contract for this year."
message.attach(MIMEText(body, "plain"))
with open(pdf_path, "rb") as attachment:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header(
"Content-Disposition",
f"attachment; filename= {pdf_path}",
)
message.attach(part)
with smtplib.SMTP("smtp.gmail.com", 587) as server:
server.starttls()
server.login(sender_email, sender_password)
server.sendmail(sender_email, employee_email, message.as_string())