Results 1 to 1 of 1

Macro - Word Mail Merge into separate documents as PDF's

Threaded View

  1. #1
    Registered User
    Join Date
    03-02-2017
    Location
    Chicago, IL
    MS-Off Ver
    2010
    Posts
    1

    Macro - Word Mail Merge into separate documents as PDF's

    Hi, I've used the below listed macro for years with out issue, and today I receive a Run-time error "5631" and for the life of me am not able to fix it. I modified the .FirstRecord and .LastRecord code but it will only PDF the first document and not all 350+ I need. Any suggestions? I am by no means any sort of an expert.

    Thanks!! Tanja


    Sub Merge_to_pdf() '
    ' merge1record_at_a_time Macro
    '
    '
        Dim fd As FileDialog
    
    
        'Create a FileDialog object as a Folder Picker dialog box.
        Set fd = Application.FileDialog(msoFileDialogFolderPicker)
        With fd
    
    
            'Use the Show method to display the Folder Picker dialog box and return the user's action.
            'The user pressed the button.
            If .Show = -1 Then
                    For Each vrtSelectedItem In .SelectedItems
    
    
                    'vrtSelectedItem is aString that contains the path of each selected item.
                    'You can use any file I/O functions that you want to work with this path.
                    'This example displays the path in a message box.
            SelectedPath = vrtSelectedItem
    
    
            Next vrtSelectedItem
    
    
            Else
            MsgBox ("No Directory Selected.  Exiting")
            Exit Sub
            End If
        End With
    
    
        'Set the object variable to Nothing.
        Set fd = Nothing
    
    
    Application.ScreenUpdating = False
    
    
    MainDoc = ActiveDocument.Name
        ChangeFileOpenDirectory SelectedPath
        For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
            With ActiveDocument.MailMerge
                .Destination = wdSendToNewDocument
                .SuppressBlankLines = True
                With .DataSource
                    .FirstRecord = i
                    .LastRecord = i
                    .ActiveRecord = i
                    docName = .DataFields("Employee_Name").Value & " PSU" & ".pdf"       ' ADDED CODE
                End With
                .Execute Pause:=False
        Application.ScreenUpdating = False
                
            End With
        ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, _
            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 SaveChanges:=False
        
    
        Next i
    Application.ScreenUpdating = True
    
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 03-02-2017 at 09:15 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Mail Merge Excel Info into Multiple Different Word Documents
    By hilarymorton2003 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2016, 12:28 AM
  2. Excel/Word Mail Merge, saving as individual documents using two mergefields as name
    By flakjack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2016, 12:34 PM
  3. Macro to split mail merge into separate documents (MAC)
    By baobei in forum Word Formatting & General
    Replies: 5
    Last Post: 10-22-2015, 07:06 PM
  4. Replies: 0
    Last Post: 09-11-2015, 09:11 AM
  5. [SOLVED] Macro for mail merge and save as word documents
    By aganesan99 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2013, 09:16 AM
  6. Macro to merge Excel information and Word documents?
    By danb1985 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-25-2010, 06:14 PM
  7. how do I use mail merge in excel for word documents
    By Lisa J Duffy in forum Excel General
    Replies: 1
    Last Post: 08-04-2005, 09:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1