Re: Using VBA to split a document into sections



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


.



Relevant Pages

  • Re: flash
    ... The error was 'BadMatch (invalid parameter attributes)'. ... you will receive the error a while after causing it. ... To debug your program, run it with the --sync command line ...
    (freebsd-questions)
  • Re: Open Default Mail Client
    ... to HKLM to get the command line. ... you would be left with an empty string now. ... by removing everything beyond the quotation mark (assuming ... to start the mail program. ...
    (borland.public.delphi.nativeapi)
  • Re: Command-line mail program that can send mail FROM multiple accounts?
    ... I'm thinking of setting up an SSH server, fetchmail ... > and a command line mail program so she can check/send email remotely ...
    (Fedora)
  • Re: I have no clue how to describe this
    ... "Alan C. Sheffield" <asheffield @ park west gallery.com> wrote: ... >out what command is causing this. ... >the next program run in that VFP session display the results of any ...
    (microsoft.public.fox.programmer.exchange)
  • Re: recent problem with TOC creation | hyperref
    ... you said that chapter 0 was causing the problem. ... I removed the \markbothcommand from the chapter. ... If you want to change the headers, ... \documentclass{memoir}%vvvv assumed that you were using memoir ...
    (comp.text.tex)