Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

find text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laura - 23 Oct 2006 14:47 GMT
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
Graham Mayor - 23 Oct 2006 15:37 GMT
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.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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'
[quoted text clipped - 39 lines]
>            Loop
> End With
Dave Lett - 23 Oct 2006 15:38 GMT
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

>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 *.
[quoted text clipped - 41 lines]
>            Loop
> End With
Laura - 23 Oct 2006 15:58 GMT
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

> 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
[quoted text clipped - 57 lines]
> >            Loop
> > End With
Graham Mayor - 24 Oct 2006 07:32 GMT
The second of the three examples quoted in my earlier post will do that!

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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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 *
[quoted text clipped - 85 lines]
>>>            Loop
>>> End With
Helmut Weber - 23 Oct 2006 15:51 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Greg Maxey - 23 Oct 2006 15:52 GMT
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

> 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 *.
[quoted text clipped - 39 lines]
>             Loop
> End With
Laura - 24 Oct 2006 08:42 GMT
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
Graham Mayor - 24 Oct 2006 09:26 GMT
More than one last digit - search for:
D\*?@[0-9])([0-9]{1,}^13)

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> thank you!
> finally I've use the solution of Greg, because the number before the
[quoted text clipped - 6 lines]
>
> in other ocassions , I will  tried to put clearest  examples
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.