Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2014, 05:07 AM
macropod's Avatar
macropod macropod is offline Split a word document Windows 7 32bit Split a word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,526
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


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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split a word document split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Split a word document 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 a word document Split multi-page mail merge document, then name file from letter info. BriMan83 Mail Merge 1 04-24-2013 11:35 PM
Split a word document Split Screen in Word Topas Word 2 05-17-2012 07:27 AM
Split a word document Split MailMerge document agujoa Mail Merge 3 04-08-2012 11:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:16 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft