Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 

Tags
mailmerge, ms word, vba

Thread Tools
Display Modes


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 12:24 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