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) get evaluated and then their compensation is recalculated and an employment contract sent to them for the next year. The contract is in PDF form which they digitally sign and return to the company. Right now the process is like this:
- A spreadsheet is created with all the employee specific information.
- The spreadsheet data is merged with the standard employment agreement based on their title.
- The merge creates a different document for each employee which must then be saved (named with the employee name), converted to a PDF, and then a digital signature is requested via Adobe.
I would like to automate this whole procedure. I would like to mail merge, save each document as a Word Doc and then a PDF under the employee's name. Once I have all of that, I would like to get PDF to send out all the documents via email (which will be in the spreadsheet too).
I am a programmer so code does not scare me in the least. I am just not sure of the approach to take.
Any thoughts? Thanks in advance.
2 Replies
Sort By
Use the Merge to Individual Documents facility of my Merge Tools Add-in that is contained in the MERGE TOOLS ADD-IN.zip file that you can download from:
https://mergetoolsaddin.com/
Extract the files from the archive and read the:
“READ ME – Setting up and using the Merge Tools Add-in.pdf
to see how to install and use the various tools.
Using those tools, it is possible to perform the following types of merge that cannot be done with Mail Merge “out-of-the-box”:
- Merge to e-mail messages either with or without attachments, with the documents created by the merge being sent as either Word or PDF attachments or as the body of the e-mail message . The email messages can, if necessary, also be sent to CC and BCC addresses and the subject of the message can include data from a field in the data source.
- Merge to individual documents in either Word or PDF format with the filenames being supplied by the data in one of the fields in the data source
- Many to One type merges, which can be used for creating documents such as invoices where there are multiple records in the data source that have common data in one of the fields
- Merging to a document that will include a chart that is unique to each record in the data source
- Merging a document with Content Controls
- Merging a document that contains Legacy FormFields
- Duplex Merges
- Merging to a printer that will collate and staple the output created from each record in the data source.
The requirements for using the system are:
- The mail merge main document must be of the Letters type, though that does not mean that the output cannot be sent as an e-mail message where relevant.
- For the Many To One, Merge with Attachments and Merge to Individual Docs utilities, the data source may be either a table or query in an Access database, or in the form of an Excel worksheet. For the Chart Merge utility, see the Mail Merging with Charts document that is included in the Merge Tools Add-in Zip file for additional requirements for the data source for use with that utility
- For a data source in the form of an Excel worksheet, the field names must be in the first row of the worksheet and there must be a field name in all of the cells in that row that are within the range of columns that contain the data.
- For both types of data source, the field names must contain only alphanumeric characters (No @,#,$,%,&,(,), etc) and the field names must not start with a numeric character (0-9). The number of characters in the field names, including spaces, must not be more than 40.
The MergeTools Add-in will NOT work with the “New Outlook”, which is just a re-badged version of Windows Mail and like its predecessor, it does not support automation and hence will not send the messages created by the MergeTools Add-in.
Be aware, that any messages that you had tried to send with the “New Outlook” will have been placed in the Outbox of the original Outlook and they will be sent as soon as you revert to that version of Outlook. If you do not want that to happen, you should put Outlook Off-line, or disconnect your computer from the Internet.
For a demonstration of the use of the facility, prepared by a Microsoft employee, see
https://www.youtube.com/watch?v=yj_s3cdfVDY
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())