Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2016, 02:28 PM
jeffreybrown jeffreybrown is offline Formatting all tables in doc with specific word in title Windows Vista Formatting all tables in doc with specific word in title Office 2007
Expert
Formatting all tables in doc with specific word in title
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Formatting all tables in doc with specific word in title

I've been able to cobble this macro together to format all tables in the doc which the first row of the table begins with either "Table" of "Figure".



Two questions:

1) How can I modify a style so it will produce TNR and 10 along with the alignment. I've tried to modify "Table Grid", but everything I read shows says this can't be modified as it is based on "Table Normal" and that you can't modify? The doc is all TNR 12 except for the body of a Table which is 10. Table header also remains 12 which I set to "Strong" in the macro below.

2) Also, are there any areas in this macro that could be modified to further use any built in styles within Word?

Code:
Sub FormatFirstTableRow()
    Dim Tbl As Table
    Dim i As Long
    Dim iRow As Row
    Application.ScreenUpdating = False
    For Each Tbl In ActiveDocument.Tables
        With Tbl
            .Range.Font.Name = "Times New Roman"
            .Range.Font.Size = 10
            .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
            .Rows(1).Select
            If InStr(1, Selection.text, "Table") = 1 Or InStr(1, Selection.text, "Figure") = 1 Then
                With .Rows(1)
                    .Range.Style = "Strong"
                    .Borders.Enable = False
                    .Borders(wdBorderBottom).LineStyle = Options.DefaultBorderLineStyle
                    .Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
                    .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
                End With
                .AutoFitBehavior (wdAutoFitContent)
                .Rows.HeightRule = wdRowHeightExactly
                .Rows.Height = InchesToPoints(0.2)
            End If
        End With
    Next
    ActiveDocument.Fields.Update
    Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 05-01-2016, 05:41 PM
macropod's Avatar
macropod macropod is offline Formatting all tables in doc with specific word in title Windows 7 64bit Formatting all tables in doc with specific word in title Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Quote:
Originally Posted by jeffreybrown View Post
1) How can I modify a style so it will produce TNR and 10 along with the alignment.
Why not create a Style with the required attributes? If you add that Style to the document template, it will be available any time you need it. See:
http://www.dummies.com/how-to/conten...word-2013.html
http://www.dummies.com/how-to/conten...word-2010.html
http://www.addbalance.com/usersguide/styles.htm
Quote:
Originally Posted by jeffreybrown View Post
2) Also, are there any areas in this macro that could be modified to further use any built in styles within Word?
Well, if you create a Style named 'Tbl', whose attributes correspond to:
Code:
            .Range.Font.Name = "Times New Roman"
            .Range.Font.Size = 10
            .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
you could replace all those lines with:
Code:
            .Range.Style = "Tbl"
Similarly, if you create a Style named 'TblHdr', whose attributes correspond to:
• Name = "Times New Roman"
• Size = 10
• Bold = True
• Alignment = wdAlignParagraphLeft
you could replace:
Code:
                    .Range.Style = "Strong"
                    .Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
with:
Code:
                    .Range.Style = "TblHdr"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-01-2016, 06:05 PM
jeffreybrown jeffreybrown is offline Formatting all tables in doc with specific word in title Windows Vista Formatting all tables in doc with specific word in title Office 2007
Expert
Formatting all tables in doc with specific word in title
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Okay, thanks Paul...works great. I was so focused on that Table Grid and Table Normal I missing this part about creating the new styles. Appreciate your assistance as always.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting all tables in doc with specific word in title VBA Word - Format ALL Tables - Apply Specific Formatting to Sets of Columns – Font, Border & Width jc491 Word VBA 10 11-04-2015 04:02 PM
Export calendar events from multiple calendars with specific title rasmus Outlook 0 02-06-2015 01:58 AM
Formatting contents after Tab of continuous lines or formatting specific area of word pawii Word 1 05-12-2014 05:24 AM
formatting specific area of word like we do in office star application pawii Word 0 05-06-2014 08:41 AM
Formatting all tables in doc with specific word in title True Title Case for First Row of All Tables Marrick13 Word VBA 14 12-11-2013 09:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:56 AM.


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