M
MichaelB
Hello,
I have the below macro which reformats tables for me when certain criteria
is met. I need to implement a section into each condition that would set the
text style to “Table Paragraph 1†for all the text within the table. It
would be ideal to do this without removing any BOLDED text that currently
exists within the cells, but I know this may be impossible. My end result is
to have all the text within my tables be formatted with the “Table Paragraph
1†style although I do have several hundred cells where the first sentence is
bolded. Maybe it is best to do this one at a time..?
Any help would be greatly appreciated??
Thx
Mike
' Macro to identify text within the first cell of a table and calculate the
number
' of columns. Depending on criteria the macro will modify the tables
accordingly.
' Note this macro works backwards starting from the end of the document
processing
' toward the top.
Sub ResizeTables()
Dim oTbl As Table
Dim iTbl As Integer
Dim oCl As Cell
Dim oRng As Range
For iTbl = ActiveDocument.Tables.Count To 1 Step -1
Set oTbl = ActiveDocument.Tables(iTbl)
Set oCl = oTbl.Cell(1, 1)
Set oRng = oCl.Range
oRng.MoveEnd Unit:=wdCharacter, Count:=-1
If oTbl.Columns.Count = 4 And oRng.Text = "Version" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.88)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.94)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(3#)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Name" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.31)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(2.56)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(0.95)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Document Name" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.31)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(2.56)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(0.95)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Requirement" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1#)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(0.69)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.63)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(3#)
End If
If oTbl.Columns.Count = 5 And oRng.Text = "Item" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.44)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(0.69)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.63)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(1.65)
ActiveDocument.Tables(iTbl).Columns(5).PreferredWidth =
InchesToPoints(1.65)
End If
If oTbl.Columns.Count = 5 And oRng.Text = "AC" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.64)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(2.19)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(1.25)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(1.19)
ActiveDocument.Tables(iTbl).Columns(5).PreferredWidth =
InchesToPoints(1.14)
End If
If oTbl.Columns.Count = 2 And oRng.Text = "Term" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
' ActiveDocument.Tables(iTbl).Rows.DistanceLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.56)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(3.75)
End If
Next iTbl
End Sub
I have the below macro which reformats tables for me when certain criteria
is met. I need to implement a section into each condition that would set the
text style to “Table Paragraph 1†for all the text within the table. It
would be ideal to do this without removing any BOLDED text that currently
exists within the cells, but I know this may be impossible. My end result is
to have all the text within my tables be formatted with the “Table Paragraph
1†style although I do have several hundred cells where the first sentence is
bolded. Maybe it is best to do this one at a time..?
Any help would be greatly appreciated??
Thx
Mike
' Macro to identify text within the first cell of a table and calculate the
number
' of columns. Depending on criteria the macro will modify the tables
accordingly.
' Note this macro works backwards starting from the end of the document
processing
' toward the top.
Sub ResizeTables()
Dim oTbl As Table
Dim iTbl As Integer
Dim oCl As Cell
Dim oRng As Range
For iTbl = ActiveDocument.Tables.Count To 1 Step -1
Set oTbl = ActiveDocument.Tables(iTbl)
Set oCl = oTbl.Cell(1, 1)
Set oRng = oCl.Range
oRng.MoveEnd Unit:=wdCharacter, Count:=-1
If oTbl.Columns.Count = 4 And oRng.Text = "Version" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.88)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.94)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(3#)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Name" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.31)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(2.56)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(0.95)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Document Name" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.31)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(1.5)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(2.56)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(0.95)
End If
If oTbl.Columns.Count = 4 And oRng.Text = "Requirement" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1#)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(0.69)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.63)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(3#)
End If
If oTbl.Columns.Count = 5 And oRng.Text = "Item" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.44)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(0.69)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(0.63)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(1.65)
ActiveDocument.Tables(iTbl).Columns(5).PreferredWidth =
InchesToPoints(1.65)
End If
If oTbl.Columns.Count = 5 And oRng.Text = "AC" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowRight
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(0.64)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(2.19)
ActiveDocument.Tables(iTbl).Columns(3).PreferredWidth =
InchesToPoints(1.25)
ActiveDocument.Tables(iTbl).Columns(4).PreferredWidth =
InchesToPoints(1.19)
ActiveDocument.Tables(iTbl).Columns(5).PreferredWidth =
InchesToPoints(1.14)
End If
If oTbl.Columns.Count = 2 And oRng.Text = "Term" Then
ActiveDocument.Tables(iTbl).Rows.Alignment =
wdAlignRowLeft
' ActiveDocument.Tables(iTbl).Rows.DistanceLeft
ActiveDocument.Tables(iTbl).AutoFitBehavior
Behavior:=wdAutoFitFixed
ActiveDocument.Tables(iTbl).Columns.PreferredWidthType =
wdPreferredWidthPoints
ActiveDocument.Tables(iTbl).Columns(1).PreferredWidth =
InchesToPoints(1.56)
ActiveDocument.Tables(iTbl).Columns(2).PreferredWidth =
InchesToPoints(3.75)
End If
Next iTbl
End Sub