From: Keith G Hicks on
Word 2003

I have some documents where many lines are like this:

(1) book 1 page 4 line 2-4
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(2) book 1 page 5 line 7-12
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(3) book 1 page 12 line 9
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(4) book 1 page 13 line 7
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(5) book 1 page 21 line 1-8
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(6) book 1 page 45 line 9-45
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(7) book 1 page 67 line 1-10
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(8) book 1 page 70 line 5-8
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(9) book 1 page 72 line 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus
(10) book 1 page 99 line 17-18
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
dolor et ligula iaculis tempus

and so on...

I'm trying to write vba code to find each line that starts wiht the number
in parens, jump to the end of that line, remove the ^p and add several
spaces so the result is this:

(1) book 1 page 4 line 2-4 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(2) book 1 page 5 line 7-12 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(3) book 1 page 12 line 9 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(4) book 1 page 13 line 7 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(5) book 1 page 21 line 1-8 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(6) book 1 page 45 line 9-45 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(7) book 1 page 67 line 1-10 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(8) book 1 page 70 line 5-8 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(9) book 1 page 72 line 1 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
(10) book 1 page 99 line 17-18 Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus

My code for finding the number in parens is fine but the rest is eluding me.
I'm completely unsure about how to do this.

Here's are the couple of ideas I'm messing with but they're not really
working right:

'Move the start of text up to the same line the citation is on
' With Selection
' .HomeKey wdStory
' With .Find
' .ClearFormatting
' .Replacement.ClearFormatting
' While .Execute(findtext:="\([0-9]{1,2}\)",
MatchWildcards:=True)
' 'Find the next line feed and remove it (this should be the
one at the end of the line)
' .ClearFormatting
' .Replacement.ClearFormatting
' If .Execute(findtext:="^p", MatchWildcards:=False) Then
' 'Selection.MoveRight wdCharacter, 1
' '.Text = "^p"
' '.Replacement.Text = ""
' '.Execute Replace:=wdReplaceOne
' End If
' 'Set oRng = Selection.Range
' Wend
' End With
' End With

Dim bCitationFound As Boolean
bCitationFound = True
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
While bCitationFound
With Selection.Find
.Text = "\([0-9]{1,2}\)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
If Selection.Find.Found Then
bCitationFound = True
Selection.EndKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=" "
End If
Wend


Thanks,

Keith


From: macropod on
Hi Keith,

Try using a wildcard Find/Replace with:
Find = '(\([0-9]{1,}\)[^32-^255]{1,})^13'
Replace = '\1 '
(omitting the tick marks in both cases)

No macro required (though you could use one, somply recording the above).

--
Cheers
macropod
[Microsoft MVP - Word]


"Keith G Hicks" <krh(a)comcast.net> wrote in message news:erQ$%23%23NgKHA.5608(a)TK2MSFTNGP05.phx.gbl...
> Word 2003
>
> I have some documents where many lines are like this:
>
> (1) book 1 page 4 line 2-4
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (2) book 1 page 5 line 7-12
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (3) book 1 page 12 line 9
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (4) book 1 page 13 line 7
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (5) book 1 page 21 line 1-8
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (6) book 1 page 45 line 9-45
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (7) book 1 page 67 line 1-10
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (8) book 1 page 70 line 5-8
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (9) book 1 page 72 line 1
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
> (10) book 1 page 99 line 17-18
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris adipiscing
> dolor et ligula iaculis tempus
>
> and so on...
>
> I'm trying to write vba code to find each line that starts wiht the number
> in parens, jump to the end of that line, remove the ^p and add several
> spaces so the result is this:
>
> (1) book 1 page 4 line 2-4 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (2) book 1 page 5 line 7-12 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (3) book 1 page 12 line 9 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (4) book 1 page 13 line 7 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (5) book 1 page 21 line 1-8 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (6) book 1 page 45 line 9-45 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (7) book 1 page 67 line 1-10 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (8) book 1 page 70 line 5-8 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (9) book 1 page 72 line 1 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
> (10) book 1 page 99 line 17-18 Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>
> My code for finding the number in parens is fine but the rest is eluding me.
> I'm completely unsure about how to do this.
>
> Here's are the couple of ideas I'm messing with but they're not really
> working right:
>
> 'Move the start of text up to the same line the citation is on
> ' With Selection
> ' .HomeKey wdStory
> ' With .Find
> ' .ClearFormatting
> ' .Replacement.ClearFormatting
> ' While .Execute(findtext:="\([0-9]{1,2}\)",
> MatchWildcards:=True)
> ' 'Find the next line feed and remove it (this should be the
> one at the end of the line)
> ' .ClearFormatting
> ' .Replacement.ClearFormatting
> ' If .Execute(findtext:="^p", MatchWildcards:=False) Then
> ' 'Selection.MoveRight wdCharacter, 1
> ' '.Text = "^p"
> ' '.Replacement.Text = ""
> ' '.Execute Replace:=wdReplaceOne
> ' End If
> ' 'Set oRng = Selection.Range
> ' Wend
> ' End With
> ' End With
>
> Dim bCitationFound As Boolean
> bCitationFound = True
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> While bCitationFound
> With Selection.Find
> .Text = "\([0-9]{1,2}\)"
> .Replacement.Text = ""
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchAllWordForms = False
> .MatchSoundsLike = False
> .MatchWildcards = True
> End With
> Selection.Find.Execute
> If Selection.Find.Found Then
> bCitationFound = True
> Selection.EndKey Unit:=wdLine
> Selection.Delete Unit:=wdCharacter, Count:=1
> Selection.TypeText Text:=" "
> End If
> Wend
>
>
> Thanks,
>
> Keith
>
>
From: Keith G Hicks on
Thanks. That worked except I had to add ^10 cuz it's CR and LF at the end of
each line.


"macropod" <macropod(a)invalid.invalid> wrote in message
news:eEzQ1yOgKHA.1648(a)TK2MSFTNGP05.phx.gbl...
> Hi Keith,
>
> Try using a wildcard Find/Replace with:
> Find = '(\([0-9]{1,}\)[^32-^255]{1,})^13'
> Replace = '\1 '
> (omitting the tick marks in both cases)
>
> No macro required (though you could use one, somply recording the above).
>
> --
> Cheers
> macropod
> [Microsoft MVP - Word]
>
>
> "Keith G Hicks" <krh(a)comcast.net> wrote in message
> news:erQ$%23%23NgKHA.5608(a)TK2MSFTNGP05.phx.gbl...
>> Word 2003
>>
>> I have some documents where many lines are like this:
>>
>> (1) book 1 page 4 line 2-4
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (2) book 1 page 5 line 7-12
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (3) book 1 page 12 line 9
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (4) book 1 page 13 line 7
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (5) book 1 page 21 line 1-8
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (6) book 1 page 45 line 9-45
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (7) book 1 page 67 line 1-10
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (8) book 1 page 70 line 5-8
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (9) book 1 page 72 line 1
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>> (10) book 1 page 99 line 17-18
>> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris
>> adipiscing dolor et ligula iaculis tempus
>>
>> and so on...
>>
>> I'm trying to write vba code to find each line that starts wiht the
>> number in parens, jump to the end of that line, remove the ^p and add
>> several spaces so the result is this:
>>
>> (1) book 1 page 4 line 2-4 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (2) book 1 page 5 line 7-12 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (3) book 1 page 12 line 9 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (4) book 1 page 13 line 7 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (5) book 1 page 21 line 1-8 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (6) book 1 page 45 line 9-45 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (7) book 1 page 67 line 1-10 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (8) book 1 page 70 line 5-8 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (9) book 1 page 72 line 1 Lorem ipsum dolor sit amet, consectetur
>> adipiscing elit. Mauris adipiscing dolor et ligula iaculis tempus
>> (10) book 1 page 99 line 17-18 Lorem ipsum dolor sit amet,
>> consectetur adipiscing elit. Mauris adipiscing dolor et ligula iaculis
>> tempus
>>
>> My code for finding the number in parens is fine but the rest is eluding
>> me. I'm completely unsure about how to do this.
>>
>> Here's are the couple of ideas I'm messing with but they're not really
>> working right:
>>
>> 'Move the start of text up to the same line the citation is on
>> ' With Selection
>> ' .HomeKey wdStory
>> ' With .Find
>> ' .ClearFormatting
>> ' .Replacement.ClearFormatting
>> ' While .Execute(findtext:="\([0-9]{1,2}\)",
>> MatchWildcards:=True)
>> ' 'Find the next line feed and remove it (this should be
>> the one at the end of the line)
>> ' .ClearFormatting
>> ' .Replacement.ClearFormatting
>> ' If .Execute(findtext:="^p", MatchWildcards:=False) Then
>> ' 'Selection.MoveRight wdCharacter, 1
>> ' '.Text = "^p"
>> ' '.Replacement.Text = ""
>> ' '.Execute Replace:=wdReplaceOne
>> ' End If
>> ' 'Set oRng = Selection.Range
>> ' Wend
>> ' End With
>> ' End With
>>
>> Dim bCitationFound As Boolean
>> bCitationFound = True
>> Selection.HomeKey wdStory
>> Selection.Find.ClearFormatting
>> While bCitationFound
>> With Selection.Find
>> .Text = "\([0-9]{1,2}\)"
>> .Replacement.Text = ""
>> .Forward = True
>> .Wrap = wdFindContinue
>> .Format = False
>> .MatchCase = False
>> .MatchWholeWord = False
>> .MatchAllWordForms = False
>> .MatchSoundsLike = False
>> .MatchWildcards = True
>> End With
>> Selection.Find.Execute
>> If Selection.Find.Found Then
>> bCitationFound = True
>> Selection.EndKey Unit:=wdLine
>> Selection.Delete Unit:=wdCharacter, Count:=1
>> Selection.TypeText Text:=" "
>> End If
>> Wend
>>
>>
>> Thanks,
>>
>> Keith