Change capitalized words to capitalized words and bold

E

Elfego Baca

I would like to change all capitalized words to be both capitalized and bol.
It has to be a macro since my document contains thousands of CAPITALIZED
words.

I would also like to delete any parenthesized phrase inside a pair of
parenthesis , including the parenthesis that contains a a 4 digit number
somewhere between the parenthesis. In other words I would like to set up a
macro that would remove the entire parenthesis such as (born in 1989 to
Martha and Stan) but not remove the phrase and pair of parenthesis such as
(tall order for $1.95).
 
G

Graham Mayor

The first option is simple enough. The second less so. The wildcard function
is difficult (or impossible) to set up to differentiate between unknown
strings containing numbers, some of which may be wanted and others not. The
following however should do the trick.

Option Explicit
Sub BoldOrDelete()
Dim orng As Range
Dim vFindText
Dim i As Long
vFindText = Array("[A-Z]{2,}", "\(*\)")
For i = 0 To UBound(vFindText)
Set orng = ActiveDocument.Range
With orng.Find
.Text = vFindText(i)
Do While .Execute(Forward:=True, _
MatchWildcards:=True) = True
If i = 0 Then
orng.Font.Bold = True
Else
If ContainsNum(orng) = True Then
orng.Delete
End If
End If
Loop
End With
Next
End Sub

Function ContainsNum(orng As Range) As Boolean
Dim iCtr As Long
For iCtr = 1 To Len(orng.Text)
ContainsNum = IsDate("01/01/" & (Mid(orng.Text, iCtr, 4)))
If ContainsNum = True Then
Exit Function
End If
Next iCtr
End Function

http://www.gmayor.com/installing_macro.htm

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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

Top