Hi All! Is there a way that I can have a macro look for
a certain word in a report, but only when it is at the
start of a line and not in the middle of a name. For
example:

I need to delete the word "MED" out of a report. It is
on multiple lines, and the number of lines varies per
report. The word "MED" can also be found in certain
words like MEDical, interMEDiate, or arMED. How do I get
the macro to only go to the start of the line
(paragraph), grab the information I need to delete, and
then move to the start of the next line (not grabing
other words)? I have posted what I have below. Thanks
in advance and have a great weekend.

Julie

Selection.Find.ClearFormatting
With Selection.Find
.Text = "MED"
.Replacement.Text = _
"

"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do
Selection.Find.Execute
If Selection.Find.Found = True Then
Selection.MoveLeft Unit:=wdCharacter, Count:=2
Selection.MoveRight Unit:=wdCharacter,
Count:=18, Extend:=wdExtend
Selection.TypeBackspace
Else
Exit Do
End If
Loop

Re: Macro for Paragraph by JGM

JGM
Fri Dec 05 11:05:09 CST 2003

Hi Julie,

Try this:

Sub RemoveMed()

Dim myPara As Paragraph
Dim myDoc As Document

Set myDoc = ActiveDocument

For Each myPara In myDoc.Paragraphs
If LCase(myPara.Range.Words(1).Text) = "med " Then
myPara.Range.Words(1).Delete
Next myPara

End Sub

HTH
Cheers!

--
_______________________________________
Jean-Guy Marcil
jmarcil@sympatico.ca

"Julie" <anonymous@discussions.microsoft.com> a écrit dans le message de
news: 0df101c3bb4d$4ac29d50$a401280a@phx.gbl...
> Hi All! Is there a way that I can have a macro look for
> a certain word in a report, but only when it is at the
> start of a line and not in the middle of a name. For
> example:
>
> I need to delete the word "MED" out of a report. It is
> on multiple lines, and the number of lines varies per
> report. The word "MED" can also be found in certain
> words like MEDical, interMEDiate, or arMED. How do I get
> the macro to only go to the start of the line
> (paragraph), grab the information I need to delete, and
> then move to the start of the next line (not grabing
> other words)? I have posted what I have below. Thanks
> in advance and have a great weekend.
>
> Julie
>
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MED"
> .Replacement.Text = _
> "
>
> "
> .Forward = True
> .Wrap = wdFindStop
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Do
> Selection.Find.Execute
> If Selection.Find.Found = True Then
> Selection.MoveLeft Unit:=wdCharacter, Count:=2
> Selection.MoveRight Unit:=wdCharacter,
> Count:=18, Extend:=wdExtend
> Selection.TypeBackspace
> Else
> Exit Do
> End If
> Loop
>



Re: Macro for Paragraph by Ed

Ed
Fri Dec 05 13:05:41 CST 2003

As I suggested yesterday to "Ann" who had a similar situation (and to whom I
gave similar code), you might try using .Text = "^pMED". If it's the
starting text of a paragraph, then it has a paragraph mark ("^p") in front
of it. Including that in your text to search for will give you only "MED"
which follows a paragraph break, meaning that "MED" is the starting text of
a new paragraph.

Ed

"Julie" <anonymous@discussions.microsoft.com> wrote in message
news:0df101c3bb4d$4ac29d50$a401280a@phx.gbl...
> Hi All! Is there a way that I can have a macro look for
> a certain word in a report, but only when it is at the
> start of a line and not in the middle of a name. For
> example:
>
> I need to delete the word "MED" out of a report. It is
> on multiple lines, and the number of lines varies per
> report. The word "MED" can also be found in certain
> words like MEDical, interMEDiate, or arMED. How do I get
> the macro to only go to the start of the line
> (paragraph), grab the information I need to delete, and
> then move to the start of the next line (not grabing
> other words)? I have posted what I have below. Thanks
> in advance and have a great weekend.
>
> Julie
>
> Selection.Find.ClearFormatting
> With Selection.Find
> .Text = "MED"
> .Replacement.Text = _
> "
>
> "
> .Forward = True
> .Wrap = wdFindStop
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> End With
> Do
> Selection.Find.Execute
> If Selection.Find.Found = True Then
> Selection.MoveLeft Unit:=wdCharacter, Count:=2
> Selection.MoveRight Unit:=wdCharacter,
> Count:=18, Extend:=wdExtend
> Selection.TypeBackspace
> Else
> Exit Do
> End If
> Loop
>



Re: Macro for Paragraph by Julie

Julie
Mon Dec 08 14:03:04 CST 2003

Hi Ed,

Thanks for your help on this problem. For the search
text, "^pMED" didn't work, but I did put "MED " and it
worked. Thanks again and have a great day!

Julie
>-----Original Message-----
>As I suggested yesterday to "Ann" who had a similar
situation (and to whom I
>gave similar code), you might try using .Text
= "^pMED". If it's the
>starting text of a paragraph, then it has a paragraph
mark ("^p") in front
>of it. Including that in your text to search for will
give you only "MED"
>which follows a paragraph break, meaning that "MED" is
the starting text of
>a new paragraph.
>
>Ed
>
>"Julie" <anonymous@discussions.microsoft.com> wrote in
message
>news:0df101c3bb4d$4ac29d50$a401280a@phx.gbl...
>> Hi All! Is there a way that I can have a macro look
for
>> a certain word in a report, but only when it is at the
>> start of a line and not in the middle of a name. For
>> example:
>>
>> I need to delete the word "MED" out of a report. It is
>> on multiple lines, and the number of lines varies per
>> report. The word "MED" can also be found in certain
>> words like MEDical, interMEDiate, or arMED. How do I
get
>> the macro to only go to the start of the line
>> (paragraph), grab the information I need to delete, and
>> then move to the start of the next line (not grabing
>> other words)? I have posted what I have below. Thanks
>> in advance and have a great weekend.
>>
>> Julie
>>
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> .Text = "MED"
>> .Replacement.Text = _
>> "
>>
>> "
>> .Forward = True
>> .Wrap = wdFindStop
>> .Format = False
>> .MatchCase = False
>> .MatchWholeWord = False
>> .MatchWildcards = False
>> .MatchSoundsLike = False
>> .MatchAllWordForms = False
>> End With
>> Do
>> Selection.Find.Execute
>> If Selection.Find.Found = True Then
>> Selection.MoveLeft Unit:=wdCharacter,
Count:=2
>> Selection.MoveRight Unit:=wdCharacter,
>> Count:=18, Extend:=wdExtend
>> Selection.TypeBackspace
>> Else
>> Exit Do
>> End If
>> Loop
>>
>
>
>.
>

Re: Macro for Paragraph by Julie

Julie
Mon Dec 08 14:04:52 CST 2003

Thanks for your help, but this didn't work for me. I=20
used the code that I already had and I used "MED " as the=20
search text instead of "MED". Thanks for your time!

Julie
>-----Original Message-----
>Hi Julie,
>
>Try this:
>
>Sub RemoveMed()
>
>Dim myPara As Paragraph
>Dim myDoc As Document
>
>Set myDoc =3D ActiveDocument
>
>For Each myPara In myDoc.Paragraphs
> If LCase(myPara.Range.Words(1).Text) =3D "med " Then
>myPara.Range.Words(1).Delete
>Next myPara
>
>End Sub
>
>HTH
>Cheers!
>
>--
>_______________________________________
>Jean-Guy Marcil
>jmarcil@sympatico.ca
>
>"Julie" <anonymous@discussions.microsoft.com> a =E9crit=20
dans le message de
>news: 0df101c3bb4d$4ac29d50$a401280a@phx.gbl...
>> Hi All! Is there a way that I can have a macro look=20
for
>> a certain word in a report, but only when it is at the
>> start of a line and not in the middle of a name. For
>> example:
>>
>> I need to delete the word "MED" out of a report. It is
>> on multiple lines, and the number of lines varies per
>> report. The word "MED" can also be found in certain
>> words like MEDical, interMEDiate, or arMED. How do I=20
get
>> the macro to only go to the start of the line
>> (paragraph), grab the information I need to delete, and
>> then move to the start of the next line (not grabing
>> other words)? I have posted what I have below. Thanks
>> in advance and have a great weekend.
>>
>> Julie
>>
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> .Text =3D "MED"
>> .Replacement.Text =3D _
>> "
>>
>> "
>> .Forward =3D True
>> .Wrap =3D wdFindStop
>> .Format =3D False
>> .MatchCase =3D False
>> .MatchWholeWord =3D False
>> .MatchWildcards =3D False
>> .MatchSoundsLike =3D False
>> .MatchAllWordForms =3D False
>> End With
>> Do
>> Selection.Find.Execute
>> If Selection.Find.Found =3D True Then
>> Selection.MoveLeft Unit:=3DwdCharacter,=20
Count:=3D2
>> Selection.MoveRight Unit:=3DwdCharacter,
>> Count:=3D18, Extend:=3DwdExtend
>> Selection.TypeBackspace
>> Else
>> Exit Do
>> End If
>> Loop
>>
>
>
>.
>