find text

L

Laura

I have to program a macro that inserts an asteristic in a specific point of
the line, if the first character of a sentences is a ‘D’ folllowed by a *.
So, I find first .Text = "^pD*", and then I have to move the cursor until
the second asteristic, and put another *, and repeat this for all the
paragraphs (that begins by D*)
Example:
Initial:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*51
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*61

End:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*5*1
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*5*1

Below is my code, but doesn’t work correctly. Can you help me please?

With Selection.Find
.Text = "^pD*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
Do While .Found

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find
.Text = "*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="*"
End With
Loop
End With
 
G

Graham Mayor

A macro is not really required:

Are we to assume that you are to put an asterisk between the last two
characters ie 51 and 61
or are they both to be 5*1?
Is the wrap after CECOM a natural wrap in the e-mail of is it a hard return?

If the asterisk goes between the last two characters and the wrap IS a hard
return, then

Search for
(D\*?@^13?@\*[0-9])([0-9])
replace with
\1*\2

If it is a soft return and the asterisk goes between the final numbers then
Search for
(D\*?@[0-9])([0-9]^13)
replace with
\1*\2

If the first number is always a five and it is a soft return then
Search for
(D\*?@)[0-9]([0-9]^13)
replace with
\15*\2

All with the wildcard option set.
http://www.gmayor.com/replace_using_wildcards.htm

You can record the search in a macro if you like.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Dave Lett

The description of your Initial and End does not match your text description
of the problem. That is, you write that you want "to move the cursor until
the second asteristic, and put another *, and repeat this for all the
paragraphs (that begins by D*)."

HOWEVER:
In the first paragraph that begins with D*, you show that you want to move
to the THIRD asterisk of that paragraph.
In the second paragraph that begins with D*, you show that you want to move
to the FOURTH asterisk of that paragraph.
In each example, you don't tell us where you want the asterisk to appear.
You show that it finds the last asterisk of the paragraph, a number and then
inserts another asterisk.

Dave
 
H

Helmut Weber

Hi Laura,

sentence and word are concepts of natural language.
Word's definition does hardly match what humans expect.
Line is another problematic definition,
as it might change depending on the printer.

To me it seems you want to process paragraphs,
that start with "D*",
and seperate the last character from the preceding
character with an asterisk.

If so then:

Sub Macro6a()
Dim oPrg As Paragraph
For Each oPrg In ActiveDocument.Paragraphs
If Left(oPrg.Range.Text, 2) = "D*" Then
With oPrg.Range.Characters.Last
If .Previous.Previous <> "*" Then
.Previous = "*" & .Previous
End If
End With
End If
Next
End Sub

There many other ways.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Greg Maxey

Laura,

I really don't understand your example. Doesnt' the second asterisk in
the paragraph occur here:
" ...OV*INTE.."


I assume that what you want is this.

For Each paragraph that starts with D* redefind any "*##" occurence as
"*#*#"

I also assume that *61 in your initial and *5*1in your end is a typo.

You might try:
Sub Test()
Dim oPar As Paragraph
For Each oPar In ActiveDocument.Range.Paragraphs
If InStr(oPar.Range.Text, "D*") = 1 Then
With oPar.Range.Find
.Text = "(\*[0-9])([0-9])"
.MatchWildcards = True
.Replacement.Text = "\1*\2"
.Execute Replace:=wdReplaceOne
End With
End If
Next
End Sub
 
L

Laura

ups! sorry, but testing the (bad) code, i insert * in a wrong place
example. And the confusion of the position is due to I count 2 * since I
have find the D* (so, i don't count the first + of the paragraph)
Thank you
i hope to explain myself better with the exmaple

initial:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*51
D*CCM-PLVF-001-00V*VISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*61
End:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST CTA[2ª-CHA-CM=F-ECL]*5*1
D*CCM-PLVF-001-00V*VISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED CECOM ST CTA[2ª-CHA-CM=F-ECL]*6*1




Dave Lett said:
The description of your Initial and End does not match your text description
of the problem. That is, you write that you want "to move the cursor until
the second asteristic, and put another *, and repeat this for all the
paragraphs (that begins by D*)."

HOWEVER:
In the first paragraph that begins with D*, you show that you want to move
to the THIRD asterisk of that paragraph.
In the second paragraph that begins with D*, you show that you want to move
to the FOURTH asterisk of that paragraph.
In each example, you don't tell us where you want the asterisk to appear.
You show that it finds the last asterisk of the paragraph, a number and then
inserts another asterisk.

Dave

Laura said:
I have to program a macro that inserts an asteristic in a specific point of
the line, if the first character of a sentences is a 'D' folllowed by a *.
So, I find first .Text = "^pD*", and then I have to move the cursor until
the second asteristic, and put another *, and repeat this for all the
paragraphs (that begins by D*)
Example:
Initial:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*51
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED
CECOM
ST CTA[2ª-CHA-CM=F-ECL]*61

End:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*5*1
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÃA RACKS (SIRUACIÓN FINAL), ED
CECOM
ST CTA[2ª-CHA-CM=F-ECL]*5*1

Below is my code, but doesn't work correctly. Can you help me please?

With Selection.Find
.Text = "^pD*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
Do While .Found

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find
.Text = "*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="*"
End With
Loop
End With
 
G

Graham Mayor

The second of the three examples quoted in my earlier post will do that!

(D\*?@[0-9])([0-9]^13)
replace with
\1*\2

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
ups! sorry, but testing the (bad) code, i insert * in a wrong place
example. And the confusion of the position is due to I count 2 *
since I have find the D* (so, i don't count the first + of the
paragraph)
Thank you
i hope to explain myself better with the exmaple

initial:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*51
D*CCM-PLVF-001-00V*VISTA FRONTAL-BATERÍA RACKS (SIRUACIÓN FINAL), ED
CECOM ST CTA[2ª-CHA-CM=F-ECL]*61
End:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*5*1 D*CCM-PLVF-001-00V*VISTA
FRONTAL-BATERÍA RACKS (SIRUACIÓN FINAL), ED CECOM ST
CTA[2ª-CHA-CM=F-ECL]*6*1




Dave Lett said:
The description of your Initial and End does not match your text
description
of the problem. That is, you write that you want "to move the cursor
until
the second asteristic, and put another *, and repeat this for all the
paragraphs (that begins by D*)."

HOWEVER:
In the first paragraph that begins with D*, you show that you want
to move
to the THIRD asterisk of that paragraph.
In the second paragraph that begins with D*, you show that you want
to move
to the FOURTH asterisk of that paragraph.
In each example, you don't tell us where you want the asterisk to
appear.
You show that it finds the last asterisk of the paragraph, a number
and then
inserts another asterisk.

Dave

Laura said:
I have to program a macro that inserts an asteristic in a specific
point of the line, if the first character of a sentences is a 'D'
folllowed by a *. So, I find first .Text = "^pD*", and then I have
to move the cursor until the second asteristic, and put another *,
and repeat this for all the paragraphs (that begins by D*)
Example:
Initial:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED
CECOM ST CTA[2ª-CHA-CM=F-ECL]*51
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÍA RACKS (SIRUACIÓN FINAL),
ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*61

End:
A*A*PLANOS
D*CCM-PLIG-001-00V*INTERCONEXIÓN GENERAL (SIRUACIÓN FINAL), ED
CECOM ST CTA[2ª-CHA-CM=F-ECL]*5*1
D*CCM-PLVF-001-00V*V*ISTA FRONTAL-BATERÍA RACKS (SIRUACIÓN FINAL),
ED CECOM
ST CTA[2ª-CHA-CM=F-ECL]*5*1

Below is my code, but doesn't work correctly. Can you help me
please?

With Selection.Find
.Text = "^pD*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
Do While .Found

Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find
.Text = "*"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute
.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="*"
End With
Loop
End With
 
L

Laura

thank you!
finally I've use the solution of Greg, because the number before the last *
can be of more than 1 digit (character)
........*51
........*611
in this case I need this result:
........*5*1
........*6*11

in other ocassions , I will tried to put clearest examples
 
G

Graham Mayor

More than one last digit - search for:
D\*?@[0-9])([0-9]{1,}^13)


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Top