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 / November 2005

Tip: Looking for answers? Try searching our database.

Replace Dialog

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JBNewsGroup - 14 Nov 2005 08:27 GMT
Hi,

General question with WORD2000.

I have a search string for the word "degree" which is to be replaced with
the degree symbol followed by an F or C.  Since the word "degree" may have
any combination of upper and lower case letters I have search strings
defined as:

    -[Dd][Ee][Gg][Rr][Ee][Ee]>
    -[Dd][Ee][Gg][Rr][Ee][Ee][Ss]>
     [Dd][Ee][Gg][Rr][Ee][Ee]>
     [Dd][Ee][Gg][Rr][Ee][Ee][Ss]>

Is there a better way to define the search strings?

I am using the EditReplace dialog since some "degree" words may not have to
be replaced.

Thanks in advance for any hints.

Jerry Bodoff
Greg Maxey - 14 Nov 2005 09:15 GMT
Have you tried simply using degree and degrees?

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi,
>
[quoted text clipped - 18 lines]
>
> Jerry Bodoff
JBNewsGroup - 14 Nov 2005 09:43 GMT
Hi Greg,

Thanks for your response.

Yes I tried "degree" and "degrees" but because of the "-" it seems that I
could not use MatchAllWordForms and had to use MatchWildCards and
PatternMatch. If I did not have the "-" then it works with "degree" and
"degrees".

Jerry Bodoff

> Have you tried simply using degree and degrees?
>
[quoted text clipped - 20 lines]
> >
> > Jerry Bodoff
Tony Jollans - 14 Nov 2005 11:52 GMT
Can you give a bit more detail of what you're doing. Looking for all word
forms of "degree" returns degree DeGreeS, etc whether preceded by "-" or "+"
or all manner of other symbols - much the same way as your posted find text
will. How are you controlling which instances get replaced?

--
Enjoy,
Tony

> Hi Greg,
>
[quoted text clipped - 37 lines]
> > >
> > > Jerry Bodoff
JBNewsGroup - 14 Nov 2005 13:08 GMT
Hi Tony,

Here is the original code that I am trying to improve:
----------------------------------------------------------------------------
--------------------
Private Sub ConvertDegrees (FCDegree as string)     ' degree symbol and F or
C
   Dim J As Integer
   Dim DegreeText As String
   Dim FindText As String

   DegreeText  = "[Dd][Ee][Gg][Rr][Ee][Ee]"

   For J = 1 To 4
       Select Case J                                              ' Define
Search Text
            Case 1
                FindText = "-" & DegreeText & ">"
            Case 2
                FindText = " " & DegreeText & ">"
            Case 3
                FindText = "-" & DegreeText & "[Ss]>"
            Case 4
                FindText = " " & DegreeText & "[Ss]>"
       End Select

       Selection.HomeKey Unit:= wdStory            ' Start Search at start
of Document
       With Selection.Find                                     ' Check if
any FindText string
            .ClearFormatting
            .Text = FindText
           .MatchWildCards = True

           If .Execute Then                                     ' If  True
then FindString in Document
               With Dialogs(wdDialogEditReplace)   ' Use Dialogs for
interaction to determine
                                                                         '
replace or no replace
                    .Find = FindText
                    .Replace = FCDegree
                    .PatternMatch = True
                    SendKeys "%F", True                   ' Initialize
Dialog to first FindString
                    On Error Resume Next                 ' Probably do not
need, leave for now
                    If (.Show = 0) Then Exit For         ' Search & Replace
cancelled
               End With
           End If
       End With
   Next J
   Selection.HomeKey Unit:=wdStory                ' Set to start of
document for next conversion step
End Sub
----------------------------------------------------------------------------
--------------------
What I have now seems to work but there has to be a better way, especially
when I have "tons" of documents to convert.

Thanks for your help.

Jerry Bodoff

> Can you give a bit more detail of what you're doing. Looking for all word
> forms of "degree" returns degree DeGreeS, etc whether preceded by "-" or "+"
[quoted text clipped - 46 lines]
> > > >
> > > > Jerry Bodoff
Tony Jollans - 14 Nov 2005 17:25 GMT
Well, you are probably doing about as well as you can with a straightforward
Find and Replace although some crafted code could be a bit more precise.
Whether it's worth it probably depends on how often degree is prefixed with
anything other than a hyphen.

As you seem to require a manual confirmation of every replacement I'm not
sure you are gaining much over just looking for all word forms of "degree"
but, again, that would depend on the rest of the content of your documents.

--
Enjoy,
Tony

> Hi Tony,
>
[quoted text clipped - 34 lines]
>                 With Dialogs(wdDialogEditReplace)   ' Use Dialogs for
> interaction to determine

'
> replace or no replace
>                      .Find = FindText
[quoted text clipped - 75 lines]
> > > > >
> > > > > Jerry Bodoff
Graham Mayor - 14 Nov 2005 11:59 GMT
Search for
<[degrsDEGRS]{6,7}>
or if you want to tie it down even tighter
<[dD]{1}[egrEGR]{4}[eEsS]{1,2}>

See http://www.gmayor.com/replace_using_wildcards.htm

Signature

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

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

> Hi Greg,
>
[quoted text clipped - 37 lines]
>>>
>>> Jerry Bodoff
JBNewsGroup - 15 Nov 2005 10:23 GMT
Hi Graham,

Thanks a lot.  After analyzing the documents I realized that the only
conversions are when the "degree" string is preceded by any digit followed
by 1 or more "-" or blank.  Therefore, I was able to completely eliminate
the Dialogs interaction by using the following:

Search      ([0123456789])[- ]{1,}<[dD]{1}[egrEGR]{4}[eEsS]{1,2}>
Replace    \1°F   or   \1°C        (F or C passed as an argument)

I assume that the {4} after [egrEGR] also encompasses the [dD]{1}
expression.

Really appreciate your help.

Jerry Bodoff

> Search for
> <[degrsDEGRS]{6,7}>
[quoted text clipped - 44 lines]
> >>>
> >>> Jerry Bodoff
Graham Mayor - 15 Nov 2005 10:37 GMT
> I assume that the {4} after [egrEGR] also encompasses the [dD]{1}
> expression.

No - they are separate strings D or d followed by any four of the next
batch. for them to be part ofnthe same expression you would need
[degrDEGR]{5}

Signature

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

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

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

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

JBNewsGroup - 15 Nov 2005 11:21 GMT
Hi Graham,

Thanks.

Jerry Bodoff
> > I assume that the {4} after [egrEGR] also encompasses the [dD]{1}
> > expression.
>
> No - they are separate strings D or d followed by any four of the next
> batch. for them to be part ofnthe same expression you would need
> [degrDEGR]{5}
JBNewsGroup - 15 Nov 2005 00:13 GMT
Hi,

Thanks for all the suggestions and comments Greg, Tony and Graham.
I really appreciate the help.

Jerry Bodoff
> Hi,
>
[quoted text clipped - 18 lines]
>
> Jerry Bodoff
 
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.