Help on small macro that won't run

E

Elessvie

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
 
J

Jay Freedman

Elessvie said:
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
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
E

Elessvie

A-HA! Perfect! Thank you so much!

In gratitudinous thankfulhood,
-Lynne


Jay Freedman said:
Elessvie said:
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
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

HOW TO KEEP A RANGE INSIDE QUOTES? 2
Error in simple macro 3
Spaces after Em dash (Longer dash) 7
Highlight that word in a sentence 2
Check Double Spaces 1
Assessment 3
Facing Error with List 1
List 0

Top