#1
|
|||
|
|||
Macro Help!
Hi, I currently have a macro in Microsoft Word to take a mail merge and save individual files as individual pdfs. As of right now, I choose the folder to save all the files in. I would like to modify the last part to save files to a specific folder already created based on the original excel document I used to create the mail merge. Any help would be greatly appreciated!!! I pasted my macro below. Code:
Option Explicit Sub Merge_to_pdf() 'merges one record at a time to the chosen output folder Application.ScreenUpdating = False Dim strFolder As String, StrName As String, MainDoc As Document, i As Long strFolder = GetFolder If strFolder = "" Then Exit Sub Set MainDoc = ActiveDocument With MainDoc For i = 1 To .MailMerge.DataSource.RecordCount With .MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = i .LastRecord = i .ActiveRecord = i If Trim(.DataFields("Last_Name")) = "" Then Exit For StrName = .DataFields("Last_Name") & ", " & .DataFields("First_Name") End With .Execute Pause:=False End With With ActiveDocument .ExportAsFixedFormat OutputFileName:=strFolder & "" & StrName & ".pdf", ExportFormat:=wdExportFormatPDF, _ OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _ Item:=wdExportDocumentContent, IncludeDocProps:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _ KeepIRM:=True, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False .Close SaveChanges:=False End With Next i End With Application.ScreenUpdating = True End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path Set oFolder = Nothing End Function Last edited by macropod; 02-13-2017 at 02:11 PM. Reason: Added code tags & formatting |
#2
|
||||
|
||||
See Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread in the Mailmerge forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Spell check macro within macro button field doesn't work in one document | samuelle | Word VBA | 0 | 07-20-2016 02:27 AM |
Macro to add title in header is missing text once macro is run | shawnee24 | Excel Programming | 1 | 05-27-2015 11:50 PM |
Macro Question: Need help making a macro to highlight the first word in every sentence | LadyAna | Word | 1 | 12-06-2014 10:39 PM |
Macro Needed to bold specific lines and Macro to turn into CSV | anewteacher | Word VBA | 1 | 05-28-2014 03:59 PM |
custom icon, undo/redo for macro, permanent macro | Rapier | Excel | 0 | 08-05-2013 06:30 AM |