Thursday, April 2, 2009

Split Mail merge in to separate documents and save as PDF

If you are using mail merge in Microsoft Word and sending letters to many people (not emails), the last step of merging does not provide an option to split each letter in to a separate file.

Well, following is a detailed guide on how to split merge into separate documents or PDF files. It requires installing an Add in to be add to Microsoft Word.

http://www.gmayor.com/individual_merge_letters.htm

and when you use it to split each merged letter into separate document, the above puts an extra line in each document. For some of you it might not be a problem but that one extra page at the end of a document can cost most people several hours.

So here is the Fix

I assume that you have already used the above to split the merge letters into separate files in a folder. Following is what you need to do to get rid of that one extra page at the end of each document.

1. Close the actual mail merge document.

2. Select all the documents in the folder and press enter to open them, you might get the following notification depending on the number of documents (if there are too many documents, I suggest you select only what your hardware can handle at a time)









3. After all the documents are opened, go to Tools > Macro > Macros > click on Create button and paste the Following Code in the right side panel as shown in the figure below and Close Microsoft Visual Basic.






















Sub RemoveExtraPage()
'
' RemoveExtraPage Macro
' Macro recorded 01-Apr-09 by Bhojraj Parmar
'
Selection.MoveDown Unit:=wdScreen, Count:=2

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^b"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.EndKey Unit:=wdStory
Application.Keyboard (1025)
Selection.RtlPara

ActiveDocument.Save
End Sub

Sub FixAllDocs()

For Each sDocument In Application.Documents

sDocument.Activate
RemoveExtraPage
sDocument.Close


Next

End Sub


4. Now go to Tools > Macro > Macros and look for FixAllDocs







5. Select it and click on Run


You now have all the documents saved and closed and the extra page from all the opened documents was removed.