#1
|
|||
|
|||
Help with splitting word doc and keeping the same font and style.
Hi all, I'm hoping you can help.
I'm currently running a project and I'm trying to break down a word doc which includes about 100 different letters individually, which I have made using mail merge. I have been able to split the doc down however when i look at the new docs they are in a different format and I'm hoping you will be able to help me with this. The script i have used is below: Sub SplitIntoPages() Dim docMultiple As Document Dim docSingle As Document Dim rngPage As Range Dim iCurrentPage As Integer Dim iPageCount As Integer Dim strNewFileName As String Application.ScreenUpdating = False 'Makes the code run faster and reduces screen _ flicker a bit. Set docMultiple = ActiveDocument 'Work on the active document _ (the one currently containing the Selection) Set rngPage = docMultiple.Range 'instantiate the range object iCurrentPage = 1 'get the document's page count iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticP ages) Do Until iCurrentPage > iPageCount If iCurrentPage = iPageCount Then rngPage.End = ActiveDocument.Range.End 'last page (there won't be a next page) Else 'Find the beginning of the next page 'Must use the Selection object. The Range.Goto method will not work on a page Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage + 4 'Set the end of the range to the point between the pages rngPage.End = Selection.Start End If rngPage.Copy 'copy the page into the Windows clipboard Set docSingle = Documents.Add 'create a new document docSingle.Range.Paste 'paste the clipboard contents to the new document 'remove any manual page break to prevent a second blank docSingle.Range.Find.Execute Findtext:="^m", ReplaceWith:="" 'build a new sequentially-numbered file name based on the original multi-paged file name and path strNewFileName = Replace(docMultiple.FullName, ".doc", "_" & Right$("000" & iCurrentPage, 4) & ".doc") docSingle.SaveAs strNewFileName 'save the new single-paged document iCurrentPage = iCurrentPage + 1 'move to the next page docSingle.Close 'close the new document rngPage.Collapse wdCollapseEnd 'go to the next page Loop 'go to the top of the do loop Application.ScreenUpdating = True 'restore the screen updating 'Destroy the objects. Set docMultiple = Nothing Set docSingle = Nothing Set rngPage = Nothing End Sub thanks in advance for your help |
#2
|
||||
|
||||
See Individual merge letters or Merge and Split
Without debugging your macro an obvious problem seems to be at Code:
Set docSingle = Documents.Add 'create a new document Code:
Set docSingle = Documents.Add(Template:=docMultiple.FullName)
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
See also 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: Mailmerge Tips & Tricks
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Word 2010 Having more than one font for same style heading | normancamp | Word | 1 | 08-06-2018 02:21 PM |
When changing table style in Word 2010, font size seems to change but doesn't show in new tables | heartsoulliving | Word | 1 | 12-07-2016 05:17 PM |
Remove white text background (keeping the font color and page color intact | cc3125 | Word | 1 | 10-26-2015 06:44 PM |
Keeping Font Color Changes After Switching Slides | Kazumi7677 | PowerPoint | 0 | 10-15-2014 08:29 PM |
Keeping Tables from Splitting Between Pages | AlexPaoletti | Word Tables | 2 | 05-18-2010 01:17 AM |