![]() |
|
#7
|
||||
|
||||
|
The following macro splits a large document into multi-page blocks, the size of which are determined via an InputBox.
Code:
Sub DocumentSplitter()
Dim iCount As Long, iLast As Long, wdDocSrc As Document, wdDocTgt As Document
Dim RngSplit As Range, StrDocName As String, StrDocExt As String, DocFmt As Long, Rslt
Set wdDocSrc = ActiveDocument
With wdDocSrc
Rslt = InputBox("The document contains " & .ComputeStatistics(wdStatisticPages) & " pages." _
& vbCr & "What is the page block count for splitting?", "Document Splitter")
If Rslt = "" Then Exit Sub
Rslt = CLng(Rslt)
StrDocName = .FullName
StrDocExt = "." & Split(StrDocName, ".")(UBound(Split(StrDocName, ".")))
StrDocName = Left(StrDocName, Len(StrDocName) - Len(StrDocExt)) & "_"
DocFmt = .SaveFormat
On Error Resume Next
For iCount = 0 To Int(.ComputeStatistics(wdStatisticPages) / Rslt)
If .ComputeStatistics(wdStatisticPages) > Rslt Then
iLast = Rslt
Else
iLast = .ComputeStatistics(wdStatisticPages)
End If
Set RngSplit = .GoTo(What:=wdGoToPage, Name:=iLast)
Set RngSplit = RngSplit.GoTo(What:=wdGoToBookmark, Name:="\page")
RngSplit.Start = .Range.Start
Set wdDocTgt = Documents.Add(Template:=ActiveDocument.AttachedTemplate.FullName, Visible:=False)
With wdDocTgt
.Range.FormattedText = RngSplit.FormattedText
.SaveAs2 FileName:=StrDocName & iCount + 1 & StrDocExt, FileFormat:=DocFmt, AddToRecentFiles:=False
.Close
End With
RngSplit.Cut
Next iCount
Set RngSplit = Nothing
.Close Savechanges:=False
End With
Set RngSplit = Nothing: Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
split word document based on bookmarks with each new document title of the bookmark
|
megatronixs | Word VBA | 9 | 09-05-2020 02:29 PM |
How do I see one document map for each half of a split MS WORD 2010 document?
|
quickwin | Word | 3 | 07-09-2013 10:20 PM |
Split multi-page mail merge document, then name file from letter info.
|
BriMan83 | Mail Merge | 1 | 04-24-2013 11:35 PM |
Split Screen in Word
|
Topas | Word | 2 | 05-17-2012 07:27 AM |
Split MailMerge document
|
agujoa | Mail Merge | 3 | 04-08-2012 11:26 PM |