Re: Using VBA to split a document into sections



In article <u#C8f#xKHHA.2632@xxxxxxxxxxxxxxxxxxxx>, Doug Robbins - Word MVP <dkr@xxxxxxxxxxxxxxxxxx> writes
Assuming that you want the split to be between words, use

Dim srange As Range
Set srange = ActiveDocument.Range
srange.End = srange.Start + 249
Do While srange.End < ActiveDocument.Range.End
Do While srange.Characters.Last <> " "
srange.End = srange.End - 1
Loop
srange.InsertAfter vbCr & vbCr
srange.Start = srange.End + 2
srange.End = srange.Start + 249
Loop



Hi Doug

OK thanks very much for that - I'm very grateful. Sorry for posting twice.

I tried this out and it works a treat. Very neat indeed.

As a small refinement , could it be made to split the text before a space followed by any number ( 1, 2, 3, etc.) rather than just before a space? Splitting before a number followed by a full stop is another possibility.

This is because my text will always be a numbered listing , so a split just before the number would be best if possible. This will mean that the second and subsequent paragraphs will start with the next in the numbered list , rather than half-way through an item. Can this be done?

I'm grateful for your help.



Best Wishes


Colin





.



Relevant Pages

  • Re: Using VBA to split a document into sections
    ... Dim srange As Range ... Set srange = ActiveDocument.Range ... Doug Robbins - Word MVP ... srange.InsertAfter vbCr & vbCr ...
    (microsoft.public.word.vba.beginners)
  • Re: Using VBA to split a document into sections
    ... Dim srange As Range ... Set srange = ActiveDocument.Range ... srange.InsertAfter vbCr & vbCr ... Ideally it would split the passage on the page with a couple of carriage ...
    (microsoft.public.word.vba.beginners)
  • Re: Using VBA to split a document into sections
    ... do you want two of more numbered list items together provided that the ... Dim srange As Range ... srange.InsertAfter vbCr & vbCr ... OK thanks very much for that - I'm very grateful. ...
    (microsoft.public.word.vba.beginners)
  • Re: trouble in inserting a section to the report
    ... i thought if i could create template for each of these ... Heading 1 style" with the numbering setup in it and saved the template. ... Dim srange As Range ... Set srange = Selection.Sections.Range ...
    (microsoft.public.word.vba.general)
  • Re: trouble in inserting a section to the report
    ... wdWord10ListBehavior ... Don't you have the numbering setup in the Section Heading 1 style? ... Dim srange As Range ... Set srange = Selection.Sections.Range ...
    (microsoft.public.word.vba.general)

Loading