Tech Support banner

Status
Not open for further replies.
1 - 6 of 6 Posts

·
Registered
Joined
·
3 Posts
Discussion Starter · #1 ·
Hi

I have been trying for days to find the right syntax.

What I am trying to do is create a Macro to search though a word document find all UPPERCASE words and make them bold.

But can’t seem to be able to search for UPPERCASE words and change them.

Any body out there can help me with this.

Thanks in advance.
 

·
Security Manager, Analyst , Rangemaster, TSF Acade
Joined
·
39,538 Posts
Hi Dan and welcome to TSF.

Excel is more my thing but the basic principles are much the same. Basically you need to search through each word, determine if the word is uppercase and then format the font as bold. I'm not overly familiar with the Word Object Model so this is probably not very efficient, but it does seem to work. (Note you need to select the document for this to work correctly.)

Code:
Sub ChangeToBold()
Dim myDoc
Dim myText

Set myDoc = ActiveDocument.Range(Start:=0, End:=Selection.End)
For Each myText In myDoc.Words
If myText.Case = wdUpperCase Then
    myText.Font.Bold = True
End If
Next myText
End Sub
HTH

Regards
 

·
Registered
Joined
·
3 Posts
Discussion Starter · #5 ·
No i was being silly, the code works, it just it i have a ascci 127(square box) with is making it end the sub without finishing

SO i'm just trying to trap that character.
 
1 - 6 of 6 Posts
Status
Not open for further replies.
Top