Re: Using VBA to split a document into sections
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 11:19:26 +0100
The mail program has introduced a line break that splits that command
causing the problem
The command
Do While .Paragraphs(j).Range.Characters.Count + .Paragraphs(j +
1).Range.Characters.Count < 250
should all be on one line or have Visual Basic line break character inserted
in it as
Do While .Paragraphs(j).Range.Characters.Count + .Paragraphs(j + _
1).Range.Characters.Count < 250
--
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:MqaorTAWuZlFFwVX@xxxxxxxxxxxxxxxxxxxxx
In article <#EfqBQ5KHHA.1240@xxxxxxxxxxxxxxxxxxxx>, Doug Robbins - Word
MVP <dkr@xxxxxxxxxxxxxxxxxx> writes
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
Hi Doug
Thanks very much for that - what a difference a digit makes!
I couldn't get it to run , I'm afraid , with a syntax error given in this
line :
Do While .Paragraphs(j).Range.Characters.Count + .Paragraphs(j +
1).Range.Characters.Count < 250
it wouldn't run beyond this unfortunately.
I did wonder if it was a pasting error between this mail program and the
VBA screen in Word , and removed a character before the '1' in j + 1. This
ran but did give an error as you said , but also seemed to put a return
before every number.
This caused a list down the page starting with each track number - clearly
not the intention. When I cleared the error popup , the text was returned
to original format. Maybe there's another pasting glitch.
Would using the Number Full Stop as a cue be easier VBA-wise than using
Space Number , I wonder?
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
- 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: How to remove every line of text that starts with xxxxxxxxx
- 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
|