R
Ridge Kennedy
Office 2003, Windows XP
I'm working on a macro that my users can use to select a headline that is
all uppercase, and convert it to a caps/lowercase headline. Title case gets
me part of the way there, but some words, like "and" and "for" and "to,"
etc., need to be lowercase.
I have some code that seems workable -- at least it works with *one* word,
but I want to have it check a list of common words (It can never be perfect,
but it can be pretty helpful, eliminated a lot of manual editing). Seems
like making a long list of if statements would be clumsy. So I'm looking for
a way to test a list of words, and ideally, a way to make the list fairly
easy to update.
I can use the LCASE or UCASE functions to get accurate tests -- be sure the
state of capitalization of the document won't goof the comparisons.
So here's the general approach I'm taking. Pointers in good directions are
appreciated.
*******
Public Sub HeadlineWordChecker()
'a procedure to inspect each word in a block of text
' that is all uppercase, and make it caps/lowercase
' in newspaper headline fashion
Dim MyRange As Range
Dim oDoc As Document
Dim wrd As Object
Dim strWrd As String
Set oDoc = ActiveDocument
' user will be prompted to select range manually
Set MyRange = Selection.Range
Selection.Collapse wdCollapseStart ' ready to edit the headline further,
if necessary
Set wrd = MyRange.Words(1)
For Each wrd In MyRange.Words
strWrd = Trim(wrd.Text) ' trim the extra space following a word
If strWrd = "IS" Then wrd.Font.Bold = True ' making it bold for test
purposes
' code goes here to
' to say if it's not the first word, and it is on my list of words,
' make it all lower case
Next
End Sub
Any assistance appreciated.
Sincerely,
Ridge in New Joisey [Exit 145]
I'm working on a macro that my users can use to select a headline that is
all uppercase, and convert it to a caps/lowercase headline. Title case gets
me part of the way there, but some words, like "and" and "for" and "to,"
etc., need to be lowercase.
I have some code that seems workable -- at least it works with *one* word,
but I want to have it check a list of common words (It can never be perfect,
but it can be pretty helpful, eliminated a lot of manual editing). Seems
like making a long list of if statements would be clumsy. So I'm looking for
a way to test a list of words, and ideally, a way to make the list fairly
easy to update.
I can use the LCASE or UCASE functions to get accurate tests -- be sure the
state of capitalization of the document won't goof the comparisons.
So here's the general approach I'm taking. Pointers in good directions are
appreciated.
*******
Public Sub HeadlineWordChecker()
'a procedure to inspect each word in a block of text
' that is all uppercase, and make it caps/lowercase
' in newspaper headline fashion
Dim MyRange As Range
Dim oDoc As Document
Dim wrd As Object
Dim strWrd As String
Set oDoc = ActiveDocument
' user will be prompted to select range manually
Set MyRange = Selection.Range
Selection.Collapse wdCollapseStart ' ready to edit the headline further,
if necessary
Set wrd = MyRange.Words(1)
For Each wrd In MyRange.Words
strWrd = Trim(wrd.Text) ' trim the extra space following a word
If strWrd = "IS" Then wrd.Font.Bold = True ' making it bold for test
purposes
' code goes here to
' to say if it's not the first word, and it is on my list of words,
' make it all lower case
Next
End Sub
Any assistance appreciated.
Sincerely,
Ridge in New Joisey [Exit 145]