K
Keith G Hicks
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
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