Select with macro based on criteria  
Author Message
I am Josha





PostPosted: Visual Basic for Applications (VBA), Select with macro based on criteria Top

Hi,

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



Microsoft ISV Community Center Forums3  
 
 
ChasAA





PostPosted: Visual Basic for Applications (VBA), Select with macro based on criteria Top

Write a line in you document for example

Hello this is MYSELF writing this

and then run this little piece of code

Sub test()
For Each wrd In ThisDocument.Words
teststr = wrd ' store original word
If UCase(wrd) = teststr Then ' compare this word with a capitalised version and if same
MsgBox "Word is in capitals" ' display message box
End If
Next
End Sub

This goes throught each word of the document and sees if it is in capitals by comparing the original word with a capitalised version. If it is then a message will be display.

Having done this then you can see if it is your exception list.

Start with this anyway, I'm sure you figure the rest out.

If not just post back

Good luck

Chas