Consulting

Results 1 to 5 of 5

Thread: WORD MAILMERGE EXTRACT TO INDIVIDUAL PDF FILES

  1. #1
    VBAX Regular
    Joined
    May 2012
    Posts
    79
    Location

    WORD MAILMERGE EXTRACT TO INDIVIDUAL PDF FILES

    Thank you in advance for reading. I have a word mail merge document but I want which has a section break at the end of each document but what I am looking for some VBA that when run will:

    Split the mail merge
    Save to a specified folder but as a pdf file

    I have found some code on the internet but I am unable to get any of it to work.

  2. #2
    VBAX Regular
    Joined
    May 2012
    Posts
    79
    Location
    I meant to add I found the following code but it just prompts me to define a file path and then nothing more, not even a Runtime Error:

    Public Sub CreatePDF()
     '
     ' CreatePDF Macro
     '
     '
     ' From: Word 2007/2010 Mail Merge to save to individual PDF files
      
         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
     
    ThisDoc = ActiveDocument.Name
         ChangeFileOpenDirectory SelectedPath
         For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
             With ActiveDocument.MailMerge
                 .Destination = wdSendToNewDocument
                 .SuppressBlankLines = True
     ' MsgBox "Press OK"
                 With .DataSource
                     .FirstRecord = i
                     .LastRecord = i
                     .ActiveRecord = i
                     docname = .DataFields("Batch").Value & ".pdf"
                 End With
                 .Execute Pause:=False
         Application.ScreenUpdating = True
         
                 
             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 False
     '    Windows(ThisDoc).Activate
         Next i
     Application.ScreenUpdating = True
     End Sub

  3. #3
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    VBAX Regular
    Joined
    May 2012
    Posts
    79
    Location
    Quote Originally Posted by gmayor View Post
    Thanks but add ins are not permitted, work pc.

  5. #5
    But they will allow you to use macros, without the knowledge and experience to utilise them properly, that can potentially cause a lot of damage to company filing systems? Astonishing.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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