Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 12-07-2013, 08:09 PM
macropod's Avatar
macropod macropod is offline True Title Case for First Row of All Tables Windows 7 32bit True Title Case for First Row of All Tables 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

Hi Marrick,

It's been a while since you last posted!

I think you'll find the following simpler, significantly more efficient and more comprehensive:
Code:
Public Sub FormatAllTables()
Application.ScreenUpdating = False
'Sets first row of each table as a repeating header and its style to "Title"
Dim Tbl As Word.Table
For Each Tbl In ActiveDocument.Tables
  With Tbl.Rows(1)
    .HeadingFormat = True
    .Range.Style = "title"
    .Range.Case = wdTitleWord
    Call TrueTitleCase(.Range)
  End With
  Tbl.Rows(2).Range.ParagraphFormat.SpaceBefore = 3
Next Tbl
Application.ScreenUpdating = True
End Sub
 
Sub TrueTitleCase(Rng As Range)
Dim RngTxt As Range, ArrTxt(), i As Long, j As Long
'list the exceptions to look for in an array
ArrTxt = Array("A", "An", "And", "As", "At", "But", "By", _
  "For", "If", "In", "Of", "On", "Or", "The", "To", "With")
Set RngTxt = Rng
With RngTxt
  For i = 1 To .Sentences.Count
    With .Sentences(i)
      If Len(.Text) > 2 And .Characters.Last = .Cells(1).Range.Characters.Last Then .End = .End - 1
      .MoveStart wdWord, 1
      If Len(.Text) > 0 Then
        For j = LBound(ArrTxt) To UBound(ArrTxt)
          With .Find
            'replace items in the list
            .ClearFormatting
            .Replacement.ClearFormatting
            .Forward = True
            .Wrap = wdFindStop
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            .Format = False
            .MatchCase = True
            .Text = ArrTxt(j)
            .Replacement.Text = ""
            .Execute
          End With
          Do While .Find.Found = True
            If .InRange(Rng) Then
              .Text = LCase(.Text)
              .Collapse wdCollapseEnd
              .Find.Execute
            Else
              Exit Do
            End If
          Loop
        Next j
        While InStr(.Text, ":") > 0
          .MoveStartUntil ":", wdForward
          .Start = .Start + 1
          .MoveStartWhile " ", wdForward
          .Words.First.Case = wdTitleWord
        Wend
      End If
    End With
  Next i
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
True Title Case for First Row of All Tables Task Indicator - All predecessors complete true/false, y/n jdove78 Project 2 10-10-2012 05:53 PM
IF formula returns TRUE instead of evaluating COUNTIF ColinC Excel 4 12-28-2011 08:21 AM
Another Case of Automatic/Zombie Formatting of Tables MKummerfeldt Word Tables 0 10-31-2011 10:40 AM
True Title Case for First Row of All Tables Macro not staying true oluc Word VBA 4 11-21-2010 08:10 AM
True Title Case for First Row of All Tables From all UPPER CASE to Proper Case davers Word 1 04-30-2009 12:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:14 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