Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Macro to toggle case?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carrie Downes - 22 Dec 2004 19:14 GMT
I'm trying to create a basic editorial macro that will search for text in
small caps and replace it with regular text in "Title Case" (first letter of
each word selected is capitalized). Here's what I have so far, which appears
to clear the small caps but doesn't toggle the case properly:

   Selection.Find.ClearFormatting
   Selection.Find.Font.SmallCaps = True
   Selection.Range.Case = wdNextCase
   Selection.Find.Replacement.ClearFormatting
   Selection.Find.Replacement.Font.SmallCaps = False
   With Selection.Find
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .format = True
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

Is there a way to modify this so that I can specifically have it changed to
Title Case? Help is much appreciated! Thanks in advance.
Carrie Downes - 22 Dec 2004 19:49 GMT
Actually, is there a way to specify ANY particular case style as the
replacement text in the macro, whether it's lowercase, title case, sentence
case, etc.? Now that I'm looking at what I need to do, I think changing it to
lowercase would be more practical for my purposes. Any ideas?

> I'm trying to create a basic editorial macro that will search for text in
> small caps and replace it with regular text in "Title Case" (first letter of
[quoted text clipped - 22 lines]
> Is there a way to modify this so that I can specifically have it changed to
> Title Case? Help is much appreciated! Thanks in advance.
Jay Freedman - 22 Dec 2004 20:59 GMT
Hi Carrie,

The problem you're running into is that there are two separate "case"
mechanisms in Word.

When you type a character into a document, the underlying character code can
be either lower case or upper case, depending on whether the Shift key is
down. Regardless of how the character is displayed, that code is what gets
saved in the document file.

Separately, there are font characteristics for Small Caps and All Caps. If
the underlying character code is lower case, then applying one of these
changes the way the character is displayed/printed -- but it's still
"really" lower case. (If the underlying character is upper case, applying
one of the formats has no effect.) Notice that there is *no* font formatting
that applies either title case or sentence case -- it just doesn't exist.

So if your macro finds and removes any Small Caps formatting from the text,
it will appear according to its underlying "real" nature. If you were seeing
small caps before the macro, you'll see lower case afterward.

The Format > Change Case command on the menu will actually change the
underlying character codes. This is where you'll find Title Case and
Sentence Case options. In a macro, the equivalent is the .Case property of
the Selection or Range object that points to the text. However, you can't
apply this directly to the .Replacement of a Find.

This code will find text in Small Caps, and then remove the Small Caps
formatting and change the case to lower case in two separate steps.

Public Sub SmCapToLowerCase()
  Dim oRg As Range
  Set oRg = ActiveDocument.Range
  With oRg.Find
     .ClearFormatting
     .Replacement.ClearFormatting
     .Format = True
     .Text = ""
     .Font.SmallCaps = True
     .Forward = True
     .Wrap = wdFindStop

     Do While .Execute
        oRg.Font.SmallCaps = False
        oRg.Case = wdLowerCase
        oRg.Collapse wdCollapseEnd
     Loop
  End With
End Sub

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Actually, is there a way to specify ANY particular case style as the
> replacement text in the macro, whether it's lowercase, title case,
[quoted text clipped - 29 lines]
>> Is there a way to modify this so that I can specifically have it
>> changed to Title Case? Help is much appreciated! Thanks in advance.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.