I am a newbie trying to self teach VB. I am pretty useless so please be
gentle.
I am trying to write a macro to allow me to select text in MS Word based
upon its case. I want to select all the text in the document that is in all
caps. Is this possible?
Also, is it possible to exclude 34 specific two letter strings of text? The
reason for this that specific "class codes" need to appear in in caps.
Can anyone help? As i said, i am pretty useless at this stage, so sample
code would be awsome.
Josha
Do you really want to *select* the uppercase text? -- or do you want to find
it and do something with it?
At its simplest, you could use code like --
Dim pChar As Variant
For Each pChar In ActiveDocument.Characters
If pChar Like "[A-Z]" Then
...
End if
Next
"Josha" <Jo...@discussions.microsoft.com> wrote in message
news:B631DF8E-4CFA-4F42...@microsoft.com...
I used you code which worked when i inserted:
Sub Test2()
Dim pChar As Variant
For Each pChar In ActiveDocument.Characters
If pChar Like "[A-Z]" Then
pChar.Select
End If
Next
End Sub
But it would only select the last letter in the document that was caps. Any
ideas?
Thbaks
Josha
"Josha" <Jo...@discussions.microsoft.com> wrote in message
news:7375E901-DAAC-4CB8...@microsoft.com...
"Josha" <Jo...@discussions.microsoft.com> wrote in message
news:14B34489-26C6-46E3...@microsoft.com...
Go buy a book.
"Josha" <Jo...@discussions.microsoft.com> wrote in message
news:35C1D89E-4612-433C...@microsoft.com...
> ok... so would i need to use a wend command or something to loop the
> select and add the selections togeather. As i said... i have no idea.
>
AS others have said, this is easier said than done. Since you seem you
really want to do this, here is some code that will get you started. Be
warned that there are many problems ahead: Just to state one: How to deal
with compound words that needs to be capitalized (Dominican Republic)?
Also, dealing with characters in a document makes for code that is really
slow... you may want to change the approach for words, but it will still be
slow...
It would be better to find a way to do this with Find/Replace.
'_______________________________________
Dim pChar As Range
Dim rgeTemp As Range
Dim lngRgeStart As Long
Dim lngRgeEnd As Long
Dim boolFoundCaps As Boolean
lngCharCount = ActiveDocument.Characters.Count
boolFoundCaps = False
For Each pChar In ActiveDocument.Characters
If pChar Like "[A-Z]" Then
If Not boolFoundCaps Then
lngRgeStart = pChar.Start
boolFoundCaps = True
End If
Else
If boolFoundCaps Then
lngRgeEnd = pChar.Start
boolFoundCaps = False
Set rgeTemp = ActiveDocument.Range(lngRgeStart, lngRgeEnd)
If rgeTemp.Characters.Count <> 1 Then
If Not rgeTemp.Text Like "BP" And _
Not rgeTemp.Text Like "MT" And _
Not rgeTemp.Text Like "RS" Then
rgeTemp.Case = wdLowerCase
End If
End If
End If
End If
Next
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarci...@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Dim drange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[A-Z]{2,}", MatchWildcards:=True,
Wrap:=wdFindContinue, Forward:=True) = True
Set drange = Selection.Range
drange.Case = wdTitleWord
Loop
End With
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Josha" <Jo...@discussions.microsoft.com> wrote in message
news:7375E901-DAAC-4CB8...@microsoft.com...