![]() |
|
#1
|
|||
|
|||
|
I am using an excel spreadsheet as a data source for a mail merge document (MS Word 2010). The merged document contains 16 records with 6 pages per record. I would like to split the document into separate records and give each file the name of 2 merged fields (first name and surname). This is not a one off it is something that I need to do frequently. If this is possible your help would be greatly appreciated. I am at a lose! Highlander |
|
#2
|
||||
|
||||
|
See Split Merged Output to Separate Documents or, better still, Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at the top of this forum:
https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
||||
|
||||
|
In addition to Paul's comprehensive coverage at https://www.msofficeforums.com/mail-...ps-tricks.html, you may also like to consider Merge and Split or perhaps better still E-Mail Merge Add-in
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#4
|
|||
|
|||
|
Thank you very much for your replies (macropod and gmayor), it is greatly appreciated. I was hoping there would be a way of doing it within MS Word without having to use coding. When it comes to Macros and VBA I have not got a clue. I have tried to get this to work using your suggestions and coding but to be honest I have not got a clue and I am getting into a pickle.
Thank you anyway. |
|
#5
|
||||
|
||||
|
All the instructions you need are in the Mailmerge Tips and Tricks 'Sticky' thread. If you're not familiar with the use of macros, follow the links in the Introduction there. Once the fairly simple setup is done, your regular workload will be greatly simplified.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
Thanks Paul
I will take some time to read the information, I am sure I will get there! I totally agree, it will definitely help increase productivity once I get my head round it. Thank you! |
|
#7
|
|||
|
|||
|
Quote:
Gordon Code:
Sub DocumentSplitter()
Dim xDoc As Document, xNewDoc As Document
Dim xSplit As String, xCount As Long, xLast As Long
Dim xRngSplit As Range, xDocName As String, xFileExt As String
Dim xRegEx As RegExp
Dim xPageCount As Integer
Dim xShell As Object, xFolder As Object, xFolderItem As Object
Dim xFilePath As String
On Error Resume Next
Set xDoc = Application.ActiveDocument
Set xShell = CreateObject("Shell.Application")
Set xFolder = xShell.BrowseforFolder(0, "Select a Folder:", 0, 0)
If TypeName(xFolder) = "Nothing" Then Exit Sub
Set xFolderItem = xFolder.Self
xFilePath = xFolderItem.Path & "\"
Application.ScreenUpdating = False
Set xNewDoc = Documents.Add(Visible:=False)
xDoc.Content.WholeStory
xDoc.Content.Copy
xNewDoc.Content.PasteAndFormat wdFormatOriginalFormatting
With xNewDoc
xPageCount = .ActiveWindow.Panes(1).Pages.Count
L1: xSplit = InputBox("The document contains " & xPageCount & " pages." & _
vbCrLf & vbCrLf & " Please enter the page count you want to split:", "Kutools for Word", xSplit)
If Len(Trim(xSplit)) = 0 Then Exit Sub
Set xRegEx = New RegExp
With xRegEx
.MultiLine = False
.Global = True
.IgnoreCase = True
.Pattern = "[^0-9]"
End With
If xRegEx.Test(xSplit) = True Then
MsgBox "Please enter the page number:", vbInformation, "Kutools for Word"
Exit Sub
End If
If VBA.Int(xSplit) >= xPageCount Then
MsgBox "The number is greater than the document number." & vbCrLf & "Please re-enter", vbInformation, "Kutools for Word"
GoTo L1
End If
xDocName = xDoc.Name
xFileExt = VBA.Right(xDocName, Len(xDocName) - InStrRev(xDocName, ".") + 1)
xDocName = Left(xDocName, InStrRev(xDocName, ".") - 1) & "_"
xFilePath = xFilePath & xDocName
For xCount = 0 To Int(xPageCount / xSplit)
xPageCount = .ActiveWindow.Panes(1).Pages.Count
If xPageCount > xSplit Then
xLast = xSplit
Else
xLast = xPageCount
End If
Set xRngSplit = .GoTo(What:=wdGoToPage, Name:=xLast)
Set xRngSplit = xRngSplit.GoTo(What:=wdGoToBookmark, Name:="\page")
xRngSplit.Start = .Range.Start
xRngSplit.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=xFilePath & xCount + 1 & xFileExt, AddToRecentFiles:=False
ActiveWindow.Close
Next xCount
Set xRngSplit = Nothing
xNewDoc.Close wdDoNotSaveChanges
Set xNewDoc = Nothing
End With
Application.ScreenUpdating = True
End Sub
|
|
#8
|
||||
|
||||
|
Quote:
If you can use that macro, you could just as easily use either of the macros in the link I provided and avoid the problems...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word VBA - Split Document By Headings - Save File Name As Heading Name
|
jc491 | Word VBA | 7 | 01-21-2022 11:04 AM |
Save each individual merged document as its own file
|
sdemuth@earthlink.net | Mail Merge | 7 | 10-07-2019 11:21 PM |
Mail Merge - split merged documents and rename each split document based on text in header
|
FuriousD | Word VBA | 1 | 05-12-2019 04:06 AM |
Word crashes if the merged document file is closed first
|
reidtaylor | Mail Merge | 7 | 05-07-2019 04:19 AM |
How can I save a Word Document as a PDF file with a merged field filename?
|
kp2009 | Word VBA | 5 | 08-27-2015 11:45 PM |