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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding capital letters in Word 3

Status
Not open for further replies.

Sam577

Technical User
Sep 2, 2003
168
GB

Hi,
I often have to define acronyms and abbreviations in words, which are mainly capitalised, so it would be really useful to be able to do a Find on capital letters in Word (2003). In the Find box, I notice that you can find such things as 'any letter' or 'any digit', and that some have codes (such as ^$ for any letter), but I can't see anything for capital letters. Is there a way of doing this, such as a code?
Many thanks,
Sam
 
Hi.

First, under the Find/Replace dialog box, click on "More", and check "Use Wildcards"

To find single occurence of a any uppercase letter type
[A-Z]
in the find box

To find dual occurence of uppercase letters type
[A-Z][A-Z]

and so on

Member- AAAA Association Against Acronym Abusers
 
Just as an code driven expansion on this:
Code:
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
   .ClearFormatting
   .MatchWildcards = True
   .Text = "[A-Z]"
   Do While .Execute(Forward:=True) = True
      [b]If r.Start <> r.Sentences(1).Start Then[/b]
         r.Expand Unit:=wdWord
         MsgBox r.Text & vbTab & "not a sentence start."
         r.Collapse Direction:=wdCollapseEnd
      End If
   Loop
End With
Set r = Nothing
As sentences are capitalized, and probably (but not, of course, absolutely) want to be ignored, the code uses a range for the document, looks for capital letters, and then checks to see if the found capital letter is the start of a sentence. If it is the start of a sentence, it goes on to the next found capital letter.

In other words, it will ignore any capital letters that are sentence starts. This may, or may not, be useful. It would depend on whether your capitalized words are by themselves (as sentences), or not. If they are single word sentences, then they are...ummm, sentences.

In this example, I expanded the found capital letter to the entire word and displayed a message. Obviously this action would be changed to whatever you actually wanted to do with the found capital letter. If anything.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top