Skip to content

hhai93/Word-Mail-Merge-To-Inviduals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“œ Word Mail Merge To Individuals

GitHub GitHub last commit

This VBA script automates the creation of individual files from a Word document using Mail Merge with data from an Excel file. Each row in the Excel file generates a separate file (PDF, DOCX, RTF, etc.), named based on a specified column.


✨ Features

  • πŸ”— Links a Word document to an Excel data source via Mail Merge.
  • πŸ“„ Generates one file per row of data.
  • πŸ–‹οΈ Names each file using a value from a chosen Excel column.
  • 🎨 Supports multiple output formats (PDF, DOCX, RTF, HTML, etc.).

πŸ“‹ Prerequisites

  • πŸ–₯️ Microsoft Word (2010 or later) with VBA support enabled.
  • πŸ“Š An Excel file (.xlsx or .xls) containing your data.
  • πŸ“ A Word document (.docx) with Mail Merge fields configured.

πŸš€ How to Use

1. Prepare Your Files

  • πŸ“ Create a Word document with Mail Merge fields (e.g., {Name}, {Address}). Connect it to your Excel file using the Mailings tab.
  • πŸ“Š Ensure your Excel file has column headers matching the Mail Merge fields (e.g., "Name", "Address").

2. Add the VBA Script

  • Open your Word document.
  • Press Alt + F11 to launch the VBA editor.
  • Go to Insert > Module and paste the code from SaveAsInviduals.vba.
  • ✏️ Customize the script:
    • Replace "Name" with the column name for naming files (e.g., "ID", "CustomerName").
    • Update "C:\YourFolderPath\" to your desired output folder (e.g., "C:\Users\YourName\Documents\Output\"). Ensure the folder exists.
    • Change the fileFormat variable to your desired format:
      • wdFormatPDF for .pdf (default).
      • wdFormatDocumentDefault for .docx.
      • wdFormatRTF for .rtf.
      • wdFormatHTML for .html.

3. Run the Script

  • Press F5 or go to Run > Run Sub/UserForm to execute.
  • πŸŽ‰ The script will generate one file per row in your Excel data!

πŸ› οΈ Code Explanation

  • dataField: Defines the Excel column used for naming output files.
  • fileFormat: Sets the output format (e.g., PDF, DOCX). Modify this in the script to change formats.
  • GetFileExtension: Helper function to match file extensions with formats.
  • πŸ”„ The script loops through each Mail Merge record, creates a new document, and saves it in the chosen format.

⚠️ Notes

  • πŸ“‚ Keep your Excel and Word files open while running the script.
  • πŸ” If column values are duplicated, files may overwrite each other. Modify the script to append a unique identifier (e.g., row number) if needed.
  • πŸ’Ύ Back up your files before running to avoid data loss.
  • πŸ–ŒοΈ Not all formats (e.g., HTML) may preserve formatting perfectlyβ€”test your output.

🌟 Example

Excel Data

Name Address Phone
John 123 Main St 555-1234
Alice 456 Oak Ave 555-5678

Output (with fileFormat = wdFormatPDF)

  • C:\YourFolderPath\John.pdf
  • C:\YourFolderPath\Alice.pdf

About

VBA script to create individual files from Word Mail Merge using Excel data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages