Group: microsoft.public.word.vba.general
From: "Jay Freedman"
Date: Friday, February 15, 2008 11:56 AM
Subject: Re: Help on small macro that won't run

Elessvie wrote:
> Hi, everyone!
>
> I'm not a developer or professional programmer, just a budding
> amateur one at best, wanting to learn more. (I am familiar with
> basic programming concepts.) In trying to improve our lives here in
> Word, I searched for and found the following code in a post in this
> discussion group and thought I'd try it out. It would do exactly
> what we need, but the procedure doesn't run after being copied into a
> NewMacros module. Can anyone please help me, or set me in the right
> direction to figure out why it won't run? I get no error messages.
>
> We are using Word 2003 (11.8202.8132) SP2.
>
> Any help or any feedback at all on this would be very very very
> appreciated.
>
> Thank you!
>
> -Lynne
>
>
> Here's the code:
>
> Sub FindAndUnderlineTextInQuotes()
>
> 'Underlines text exclusive of the quotes marks
>
> Set oRng = ActiveDocument.Content
>
> With oRng.Find
> .ClearFormatting
> .Text = """<*>"""
> .Forward = True
> .Wrap = wdFindStop
> .MatchWildcards = True
> Do While .Execute
> If oRng.Find.Found = True Then
> With oRng
> .MoveEnd Unit:=wdCharacter, Count:=-1
> .MoveStart Unit:=wdCharacter, Count:=1
> .Font.Underline = True
> .Collapse wdCollapseEnd
> End With
> End If
> Loop
> End With
> End Sub

The macro really does run, but it doesn't find anything in the document
because it doesn't consider the possibility that the quote marks in your
document could be "curly" quotes (what Word calls smart quotes).

Change the .Text line to this, and try again:

.Text = "[^0034^0147]<*>[^0034^0148]"

In this expression, ^0034 is the decimal ASCII code for a straight quote
character, ^0147 is the code for an opening curly quote, and ^0148 is the
code for a closing curly quote.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.