Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Capitalize first letter of words 4 characters or greater if certain styles are applied:

Posted on 2012-04-13
5
Medium Priority
?
270 Views
Last Modified: 2012-04-23
Hello, I have some long documents and I want the formatting to appear uniform.  One of the rules I am trying to apply pertains to Headers and Table titles which have one of several styles applied to them.  I would also like the first letter of hyphenated words before and after the hyphen to be capitalized.

Here is an example (just imagine it has one of the relevant styles applied):

Before:
This is an incorrectly Formatted title with a non-randomly inserted hyphenated word.

After
This is an Incorrectly Formatted Title With a Non-Randomly Inserted Hyphenated Word.


The style names of interest are:
Level1Heading
Level2Heading
Level3Heading
Level4Heading
Level5Heading
Level6Heading
Level7Heading
Level8Heading
ChapterHeading
TableTitle
FrontMatterHead


Thank you for any help you can provide experts and I look forward to talking with you,
Bev
0
Comment
Question by:Bevos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 37846374
I don't see any way to tweak a style to do this.  :-(

However, you could iterate through the different styles you've listed and go to (Find) each item in your document with that style, changing the case of the found range.
Example:
Public Sub RecaseStyles()
    Dim strStyleNames() As Variant
    Dim vItem As Variant
    strStyleNames = Array("Level1Heading", "Level2Heading", "Level3Heading", _
                     "Level4Heading", "Level5Heading", "Level6Heading", "Level7Heading", _
                     "Level8Heading", "ChapterHeading", "TableTitle", "FrontMatterHead")
    For Each vItem In strStyleNames
        With ActiveDocument.Content.Find
            .ClearFormatting
            .Style = vItem
            .Execute Forward:=True, Format:=True
            Do While .Found = True
               .Parent.FormattedText.Case = wdTitleWord
               .Execute Forward:=True, Format:=True
            Loop
        End With
    Next
End Sub

Open in new window

0
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 37846422
After a second reading of your requirements, I realized that formatting the entire sentence wasn't sufficient. We have to iterate the words and check for both length and the hyphenated word.  This isn't a fool-proof routine, so you need to run it against all the possible text layouts in your documents.

Public Sub RecaseStyles()
    Dim strStyleNames() As Variant
    Dim vItem As Variant
    Dim rngWord As Range
    strStyleNames = Array("Level1Heading", "Level2Heading", "Level3Heading", _
                "Level4Heading", "Level5Heading", "Level6Heading", "Level7Heading", _
                "Level8Heading", "ChapterHeading", "TableTitle", "FrontMatterHead")
    For Each vItem In strStyleNames
        With ActiveDocument.Content.Find
            .ClearFormatting
            .Style = vItem
            .Execute Forward:=True, Format:=True
            Do While .Found = True
                For Each rngWord In .Parent.Words
                    If Len(Trim(rngWord.Text)) > 3 Then
                        rngWord.FormattedText.Case = wdTitleWord
                    End If
                    If rngWord.Text = "-" Then
                        rngWord.Previous(wdWord).FormattedText.Case = wdTitleWord
                    End If
                Next
                .Execute Forward:=True, Format:=True
            Loop
        End With
    Next
End Sub

Open in new window

0
 

Author Comment

by:Bevos
ID: 37852302
Hello, I am very excited to try the solution you posed, but when I do I get an MS Word that stops responding (this is why trying on a small ~20 page document).  Is there a reason why this might be happening for me or is it just too long for this to run?

Thanks,
Bev
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37852388
please post the document you are using for your test.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 37882273
thanks for the points.  Did you resolve the stops-responding behavior?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question