Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2017, 09:54 AM
greatlakes25 greatlakes25 is offline Macro Help! Windows 10 Macro Help! Office 2013
Novice
Macro Help!
 
Join Date: Feb 2017
Posts: 1
greatlakes25 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 02-13-2017, 02:28 PM
macropod's Avatar
macropod macropod is offline Macro Help! Windows 7 64bit Macro Help! Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

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 Help! 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft