Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-08-2021, 12:35 PM
Highlander01 Highlander01 is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Novice
Split a Merged Document & Name Each File
 
Join Date: Jan 2016
Location: Portsmouth, England
Posts: 18
Highlander01 is on a distinguished road
Default Split a Merged Document & Name Each File

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
Reply With Quote
  #2  
Old 01-08-2021, 01:13 PM
macropod's Avatar
macropod macropod is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 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]
Reply With Quote
  #3  
Old 01-09-2021, 12:22 AM
gmayor's Avatar
gmayor gmayor is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #4  
Old 01-10-2021, 12:42 PM
Highlander01 Highlander01 is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Novice
Split a Merged Document & Name Each File
 
Join Date: Jan 2016
Location: Portsmouth, England
Posts: 18
Highlander01 is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 01-10-2021, 01:00 PM
macropod's Avatar
macropod macropod is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #6  
Old 01-10-2021, 02:25 PM
Highlander01 Highlander01 is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Novice
Split a Merged Document & Name Each File
 
Join Date: Jan 2016
Location: Portsmouth, England
Posts: 18
Highlander01 is on a distinguished road
Default

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!
Reply With Quote
  #7  
Old 01-11-2021, 09:28 AM
Highlander01 Highlander01 is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Novice
Split a Merged Document & Name Each File
 
Join Date: Jan 2016
Location: Portsmouth, England
Posts: 18
Highlander01 is on a distinguished road
Default Vba

Quote:
Originally Posted by macropod View Post
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.
I found a piece of code that does exactly what I want it to do. I will read your threads further when I get the time tho'. For now I have found a piece of VBA (below) that does what I want it to do. However, it does add an additional page to each record and it creates a duplicate record for the final record in the file. Any ideas?

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
Reply With Quote
  #8  
Old 01-11-2021, 01:10 PM
macropod's Avatar
macropod macropod is offline Split a Merged Document & Name Each File Windows 10 Split a Merged Document & Name Each File Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Highlander01 View Post
I found a piece of code that does exactly what I want it to do.
Except that it doesn't...
Quote:
Originally Posted by Highlander01 View Post
However, it does add an additional page to each record and it creates a duplicate record for the final record in the file.
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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split a Merged Document & Name Each File Word VBA - Split Document By Headings - Save File Name As Heading Name jc491 Word VBA 7 01-21-2022 11:04 AM
Split a Merged Document & Name Each File Save each individual merged document as its own file sdemuth@earthlink.net Mail Merge 7 10-07-2019 11:21 PM
Split a Merged Document & Name Each File 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
Split a Merged Document & Name Each File Word crashes if the merged document file is closed first reidtaylor Mail Merge 7 05-07-2019 04:19 AM
Split a Merged Document & Name Each File 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:20 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