Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 14th, 2013, 06:09 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Loop VBA with Mail Merge

Hello,

I am working on a project in which a mail merge document will ultimately generate several PDF documents (1 PDF per Merge Record). The PDF document itself is saved with a file name based on a merge field on the master merge document. The problem I am having is finding a way to loop through to the next merge record and repeat until all merge records have generated their own PDF.

I am using the code below as a starting point:
Code:
Sub Macro1()
'
' Macro1 Macro

   With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
            .LastRecord = ActiveDocument.MailMerge.DataSource.LastRecord
        End With
        .Execute Pause:=False
    End With
    ActiveWindow.ActivePane.VerticalPercentScrolled = 64
    Selection.WholeStory
    Selection.Fields.Update
        ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        "Q:\FILE PATH\" & _
        Documents("MasterTemplate.doc").MailMerge.DataSource.DataFields("File_Name").Value & ".pdf", ExportFormat:= _
        wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, FROM:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
    ActiveWindow.Close
         
End Sub
I am working in Word 2007 and I know there are ways to merge to individual documents built in, however, I need to use the code as there is an image that is generated based on a merge field. This requires that the individual record be updated using Selection.WholeStory and Selection.Fields.Update

If anyone knows how to get this code to repeat (it works PERFECT for the first record) for each record that would be swell!

Thanks!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Mail Merge adding unwanted pages jeffalex2 Word VBA 0 July 27th, 2011 08:04 AM
Help with mail merge! N3on Excel VBA 1 July 25th, 2011 02:40 PM
Mail Merge VBA Query jayp Excel VBA 1 October 14th, 2005 05:25 PM
Need Help In Mail Merge raghur Access VBA 0 September 8th, 2005 05:46 AM
Access/Vba mail merge to word help alfonse Access VBA 0 July 28th, 2005 05:11 AM



All times are GMT -4. The time now is 08:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.