![]() |
|
#1
|
|||
|
|||
![]()
There are many solutions to run Word Mail Merges from Excel. However, I would like to do it from a WORD vba macro instead as follows: 1. Run a mail merge in Word (therefore, have the vba in Word) 2. Create a separate pdf for each form letter generated 3. Use the "Client Name" from the excel table for each Word file
So far I have the following code which only makes a pdf for the first page in the merge. I gave it the name "C:\File.pdf". However, I'd like to somehow view the mail merge/excel table as an object and go through all 602 records in a loop (there are 602 records in the excel table it is based upon) and each time it goes through the loop, it takes the "Client Name" for that record and uses that to name the pdf for that iteration. Any help is greatly appreciated. Sub PrintToPdf() Set myMerge = ActiveDocument.MailMerge If myMerge.State = wdMainAndSourceAndHeader Or _ myMerge.State = wdMainAndDataSource Then With myMerge.DataSource .FirstRecord = 1 .LastRecord = 5 End With End If With myMerge 'Next line will create pdf 'Challenge is to DIM some "merge" as ? of Item as ? and run through all in excel source 'and save PDF based on Client Name ActiveDocument.ExportAsFixedFormat OutputFileName:="C:\File.pdf", ExportFormat:=wdExportFormatPD F End With End Sub |
#2
|
||||
|
||||
![]()
Might I suggest you look at the 'Send Mailmerge Output to Individual Files' topic in the 'Mailmerge Tips & Tricks' Sticky thread at the top of this forum...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
As well as reading Paul's extensive and most useful Tips and Tricks, I have three Word template add-ins available that will do this - the obvious choice being http://www.gmayor.com/individual_merge_letters.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
Tags |
mailmerge, ms word, vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
kaan0302 | Mail Merge | 1 | 07-21-2014 05:11 AM |
Mail merge how to link mail merge field value to a column heading | dsummers | Mail Merge | 1 | 05-08-2014 02:59 PM |
Mail Merge Word Doc over SSL VPN | David92595 | Word | 0 | 08-23-2013 03:42 PM |
![]() |
mikecincotta | Mail Merge | 1 | 10-04-2010 05:22 PM |
mail merge in word help | jngovols | Mail Merge | 0 | 04-07-2008 05:40 AM |