Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 09-18-2015, 09:26 PM
macropod's Avatar
macropod macropod is offline Macro that formats (true title) case by Heading style Windows 7 64bit Macro that formats (true title) case by Heading style Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Apply_True_Title_Case_by_Style()
Application.ScreenUpdating = False
Dim StyleName As String, wrd As Long, Count As Long
Const lclist As String = " a an and as at but by for from if in is of " _
  & " on or the this to "
StyleName = "Heading 1"
With ActiveDocument
  With .Range
    With .Find
      .ClearFormatting
      .Wrap = wdFindStop
      .Forward = True
      .Format = True
      .MatchWildcards = False
      .Text = ""
      .Style = ActiveDocument.Styles(StyleName)
      .Execute
    End With
    Do While .Find.Found = True
      Count = Count + 1
      With .Duplicate
        .Case = wdTitleWord
        For wrd = 2 To .ComputeStatistics(wdStatisticWords)
          If InStr(lclist, " " & LCase(Trim(.Words(wrd))) & " ") > 0 Then _
            .Words(wrd).Case = wdLowerCase
        Next wrd
      End With
      .Collapse wdCollapseEnd
      If (ActiveDocument.Range.End - .End) < 2 Then Exit Do
      .Find.Execute
    Loop
  End With
End With
Select Case Count
Case 0
  MsgBox "Macro could not find any instances of '" & StyleName & "'.", vbOKOnly, "Results"
Case 1
  MsgBox "Macro applied true title case to 1 instance of '" & StyleName & "'.", vbOKOnly, "Results"
Case Is > 1
  MsgBox "Macro applied true title case to " & Count & " instances of '" & StyleName & "'.", vbOKOnly, "Results"
End Select
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 09-19-2015 at 06:47 PM. Reason: Code revision
Reply With Quote
 

Tags
loop style format case



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro that formats (true title) case by Heading style Tab character causes style change to Heading 4 after macro Jennifer Murphy Word VBA 2 12-14-2015 02:31 AM
Macro to create a title in the Header when a certain text style is used (such as Heading 1) Lonesy Word VBA 1 06-03-2015 03:57 AM
Macro that formats (true title) case by Heading style Customising a style that uses Title Case formatting Madanjeet Word 6 05-18-2015 10:11 AM
Macro that formats (true title) case by Heading style True Title Case for First Row of All Tables Marrick13 Word VBA 14 12-11-2013 09:12 PM
Macro that formats (true title) case by Heading style Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft