Custom Word document splitter! VBA

arvex

New Member
Joined
May 10, 2011
Messages
18
Hello experts!

I have code by Jacob Hilderbrand:

Code:
Option Explicit 
 
Sub AllSectionsToSubDoc() 
     
    Dim x               As Long 
    Dim Sections        As Long 
    Dim Doc             As Document 
     
    Application.ScreenUpdating = False 
    Application.DisplayAlerts = False 
     
    Set Doc = ActiveDocument 
    Sections = Doc.Sections.Count 
    For x = Sections - 1 To 1 Step -1 
        Doc.Sections(x).Range.Copy 
        Documents.Add 
        ActiveDocument.Range.Paste 
        ActiveDocument.SaveAs (Doc.Path & "\" & x & ".doc") 
        ActiveDocument.Close False 
    Next x 
     
    Application.ScreenUpdating = True 
    Application.DisplayAlerts = True 
     
End Sub

All i want is to work code custom like:

Split document when 7th paragraph changes!

Document is like (might be different):

PAGE1
Text
Text
Text
Text
Text
Text
Text1
Text
Text

PAGE2
Text
Text
Text
Text
Text
Text
Text1
Text
Text

PAGE3
Text
Text
Text
Text
Text
Text
Text2
Text
Text

PAGE4
Text
Text
Text
Text
Text
Text
Text3
Text
Text

PAGE5
Text
Text
Text
Text
Text
Text
Text3
Text
Text

ETC

As a result from given example I want to see is 3 Word documents:
  • 1st Word document all pages when Text1 is in paragraph 7;
  • 2nd Word document all pages when Text2 is in paragraph 7;
  • 3rd Word document all pages when Text3 is in paragraph 7;
  • ETC...

And save each document by trimmed text from 1st page 7th and 3rd paragraph of new document (of whole document each page's 3rd paragraph is different)
Save for 1st document with Text1 would be: It's "Paragraph7_Paragraph3.docx"
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,225,763
Messages
6,186,897
Members
453,384
Latest member
BigShanny

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top