F
Frank
I want to iterate through each table in a document and make som column
adjustments, see code below.
However, in order to make this work, I guess I need to select left cell in
first row in the table before performing a table column title search and the
column adjustment.
How do I select the left cell in first row in the table?
Regards
Frank Krogh
Sub AdjustTables()
Application.ScreenUpdating = False
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
FixTablesColumns
Next aTable
Application.ScreenUpdating = True
End Sub
Sub FixTablesColumns()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "given table column title"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = CentimetersToPoints(2.24)
Selection.Find.ClearFormatting
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' other table column adjustments here ...
end sub
adjustments, see code below.
However, in order to make this work, I guess I need to select left cell in
first row in the table before performing a table column title search and the
column adjustment.
How do I select the left cell in first row in the table?
Regards
Frank Krogh
Sub AdjustTables()
Application.ScreenUpdating = False
For Each aTable In ActiveDocument.Tables
aTable.AutoFitBehavior (wdAutoFitContent)
FixTablesColumns
Next aTable
Application.ScreenUpdating = True
End Sub
Sub FixTablesColumns()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "given table column title"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.SelectColumn
Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
Selection.Columns.PreferredWidth = CentimetersToPoints(2.24)
Selection.Find.ClearFormatting
Selection.MoveLeft Unit:=wdCharacter, Count:=1
' other table column adjustments here ...
end sub