Re: Using VBA to split a document into sections
- From: Colin Hayes <Colin@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Dec 2006 15:36:34 +0000
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
.
- Follow-Ups:
- Re: Using VBA to split a document into sections
- From: Doug Robbins - Word MVP
- Re: Using VBA to split a document into sections
- References:
- Using VBA to split a document into sections
- From: Colin Hayes
- Re: Using VBA to split a document into sections
- From: Doug Robbins - Word MVP
- Using VBA to split a document into sections
- Prev by Date: Re: backup to multiple folders
- Next by Date: Re: Using VBA to split a document into sections
- Previous by thread: Re: Using VBA to split a document into sections
- Next by thread: Re: Using VBA to split a document into sections
- Index(es):
Relevant Pages
|
Loading