Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word: How to find Upper Case Names and modify them

Status
Not open for further replies.

GPerk

Programmer
Jul 6, 2002
161
US
I have a file that has people's names in upper case.
How can I find these names and modify them (make lower case, make bold, etc.).
I would like to be able to restrict this to certain paragraphs in the document which have unique flags at the beginning of the paragraphs.
 
Hi GPerk,

I don't know exactly what you want here but this will identify words which are all in upper case in a document and set them to bold. You can restrict the search range to individual paragraphs or anything else you want and apply your own formatting instead of bold.

Code:
Dim tjWord As Range

For Each tjWord In ActiveDocument.Words

    If Trim(tjWord.Text) Like "*[!A-Z]*" Then
        MsgBox tjWord.Text & " Is NOT All Upper Case"
    Else
        MsgBox tjWord.Text & " Is All Upper Case"
        tjWord.Bold = True
    End If

Next

One point to watch out for. This will include words which have been formatted as 'All Caps' but which are not actually in upper case in the underlying text.

Enjoy,
Tony
 
Tony,
That code works if I process the whole document.
But when I try to select certain paragraphs, I get a "type mismatch" on the first For statement below.
Apparently I don't know how to handle ranges. Can you help?

Sub UpNames()
Dim tjWord As Range, tjPara As Range

For Each tjPara In ActiveDocument.Paragraphs
If TestPara(tjPara) Then
For Each tjWord In ActiveDocument.Words
If Trim(tjWord.Text) Like "*[!A-Z]*" Then
MsgBox tjWord.Text & " Is NOT All Upper Case"
Else
MsgBox tjWord.Text & " Is All Upper Case"
tjWord.Bold = True
End If
Next tjWord
End If
Next tjPara
End Sub

Function TestPara(ByVal P As Range) As Boolean
' test goes here
End Function
 
I think I found a way to do it at

Sub Test2()
Dim I As Integer
Dim rngPara As Range, iWord As Range

For I = 1 To ActiveDocument.Paragraphs.Count
Set rngPara = ActiveDocument.Paragraphs(I).Range
If rngPara.Characters(1) Like "*[0-9]" Then
For Each iWord In rngPara.Words
If Trim(iWord.Text) Like "*[A-Z]" Then
MsgBox iWord.Text & " is UPPER"
Else
MsgBox iWord.Text & " is lower"
End If
Next iWord
End If
Next I
End Sub

Thanks, Tony. You got me started in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top