Re: Using VBA to split a document into sections
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Dec 2006 22:55:03 +0100
I would approach that in a different way which the following macro does. It
does throw up an error message that you can just ignore. (While I know what
is causing the error, I haven't devised a method to prevent the it from
occuring)
Dim i As Long, j As Long, k As Long
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "( [0-9]{1,}.)"
.Replacement.Text = "^p\1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
i = ActiveDocument.Paragraphs.Count
j = 1
With ActiveDocument
.Paragraphs.First.Range.Characters.Last.Delete
Do While i > 0
Do While .Paragraphs(j).Range.Characters.Count + .Paragraphs(j +
1).Range.Characters.Count < 250
.Paragraphs(j).Range.Characters.Last.Delete
i = i - 1
Loop
j = j + 1
.Paragraphs(j).Range.Characters.First.Delete
Loop
End With
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Colin Hayes" <Colin@xxxxxxxxxxxxxxxxxx> wrote in message
news:AVfb0KABkWlFFwnK@xxxxxxxxxxxxxxxxxxxxx
In article <e6sqEc2KHHA.2028@xxxxxxxxxxxxxxxxxxxx>, Doug Robbins - Word
MVP <dkr@xxxxxxxxxxxxxxxxxx> writes
Do you want the split before EACH number that is followed by a full stop?
Or, do you want two of more numbered list items together provided that the
total number of characters is such group does not exceed 250?
Hi Doug
No - it would split at the same point in the text that it splits now (as
near to 250 characters as it can get) , but using Space Number as its cue
rather than Space.
It means that the second and subsequent paragraphs will start with a
number.
Here's an example :
1. Original text :
Tracks : 1. Money Money Money (3:08) 2. Honey Honey (2:55) 3. People Need
Love (2:45) 4. He Is Your Brother (3:18) 5. Ring Ring (3:04) 6. Love Isn't
Easy (2:53) 7. So Long (3:05) 8. Eagle (4:27) 9. Summer Night City (3:36)
10. Angel Eyes (4:19) 11. On And On And On (3:42) 12. When All Is Said And
Done (3:17) 13. Under Attack (3:47)
2. 250 chars split at Space:
Tracks : 1. Money Money Money (3:08) 2. Honey Honey (2:55) 3. People Need
Love (2:45) 4. He Is Your Brother (3:18) 5. Ring Ring (3:04) 6. Love Isn't
Easy (2:53) 7. So Long (3:05) 8. Eagle (4:27) 9. Summer Night City (3:36)
10. Angel Eyes (4:19) 11.
On And On And On (3:42) 12. When All Is Said And Done (3:17) 13. Under
Attack (3:47)
3. 250 chars split at Space Number
Tracks : 1. Money Money Money (3:08) 2. Honey Honey (2:55) 3. People Need
Love (2:45) 4. He Is Your Brother (3:18) 5. Ring Ring (3:04) 6. Love Isn't
Easy (2:53) 7. So Long (3:05) 8. Eagle (4:27) 9. Summer Night City (3:36)
10. Angel Eyes (4:19)
11. On And On And On (3:42) 12. When All Is Said And Done (3:17) 13. Under
Attack (3:47)
I think that a split at Space Number would be neater , if it's possible.
Thanks for your help with this.
Best Wishes
Colin
.
- Follow-Ups:
- Re: Using VBA to split a document into sections
- From: Colin Hayes
- 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
- Re: 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
- Re: Using VBA to split a document into sections
- From: Colin Hayes
- Using VBA to split a document into sections
- Prev by Date: Re: Using VBA to split a document into sections
- 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