Re: Using VBA to split a document into sections



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


.



Relevant Pages

  • Re: IIS and ASP
    ... does not sound like attack. ... The exact and complete error message ... OWA and replaces any OWA files that your company may have customized. ... If your Citrix server .ASP ...
    (microsoft.public.inetserver.iis.security)
  • Re: duplicate message removal
    ... All these servers are running denyhosts, but we still see lots of these ... I was wondering if there's any simple compression script which notices ... Attack the problem: ... hostname and error message together, but any scripting language that you're ...
    (freebsd-questions)
  • exploit signalled in Xemacs/ACL
    ... unauthorized hosts to establish a connection. ... such an attack is underway is that an error message like the following ... Does the error message from Xemacs look familiar to anyone? ...
    (comp.lang.lisp)
  • Re: October 7DRL..
    ... Crashes every time I attack a monster. ... No error message or whatever is ...
    (rec.games.roguelike.development)

Loading