Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-09-2014, 03:32 PM
dmmalkin1 dmmalkin1 is offline Running Mail Merge with vba from MS WORD Windows 7 64bit Running Mail Merge with vba from MS WORD Office 2013
Novice
Running Mail Merge with vba from MS WORD
 
Join Date: Dec 2014
Location: Earth
Posts: 1
dmmalkin1 is on a distinguished road
Smile Running Mail Merge with vba from MS WORD

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
Reply With Quote
  #2  
Old 12-09-2014, 04:39 PM
macropod's Avatar
macropod macropod is offline Running Mail Merge with vba from MS WORD Windows 7 64bit Running Mail Merge with vba from MS WORD Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,342
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 12-09-2014, 10:54 PM
gmayor's Avatar
gmayor gmayor is offline Running Mail Merge with vba from MS WORD Windows 7 64bit Running Mail Merge with vba from MS WORD Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

Tags
mailmerge, ms word, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running Mail Merge with vba from MS WORD word mail merge add cc 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
Running Mail Merge with vba from MS WORD I need MS Word Mail Merge Help! 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft