C
ckxplus
I've got tables with counts and percentages in many of the table cells
in the form "35.3% (47/133)". I want the percentages to align so I
wrote a macro to define right-aligning tab positions at 40% and 100%
of the cells usable width and then insert a tab character between the
percentage sign and the opening parenthesis. It works but it's a very
brute force method because it defines tabs in each cell of all tables
in a document. What I'd like to be able to do is to search for a cell
with percentages and counts and only then to define the tab positions.
Could someone help me out in this?
Here's my macro in its present state. It takes about 25 seconds on a
19 page document.
Public Sub TabsForPctAndCount()
Dim aRange As Word.Range
Dim oTable As Word.Table
Dim oCell As Cell
Dim UseableWidth As Single
Set aRange = ActiveDocument.Range(0, 0)
System.Cursor = wdCursorWait ' Displays the hourglass
StatusBar = "Defining tab positions in tables ..."
'Insert right aligning tab positions at 40% and 100% of each cell
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
UseableWidth = oCell.Width - oCell.LeftPadding -
oCell.RightPadding
oCell.Range.ParagraphFormat.TabStops.ClearAll
oCell.Range.ParagraphFormat.TabStops.add
Position:=UseableWidth * 0.4, Alignment:=wdAlignTabRight
oCell.Range.ParagraphFormat.TabStops.add
Position:=UseableWidth, Alignment:=wdAlignTabRight
Next oCell
Next oTable
StatusBar = "Inserting tabs between percentages and counts ..."
'Replace a "XX.X% (" by "\tXX.X%\t("
With aRange.find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9.]@%)[ ]@\("
.Replacement.Text = "^t\1^t("
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
System.Cursor = wdCursorNormal ' Normal cursor
StatusBar = "Macro TabsForPctAndCount completed."
End Sub
Thanks for any help,
John Hendrickx
in the form "35.3% (47/133)". I want the percentages to align so I
wrote a macro to define right-aligning tab positions at 40% and 100%
of the cells usable width and then insert a tab character between the
percentage sign and the opening parenthesis. It works but it's a very
brute force method because it defines tabs in each cell of all tables
in a document. What I'd like to be able to do is to search for a cell
with percentages and counts and only then to define the tab positions.
Could someone help me out in this?
Here's my macro in its present state. It takes about 25 seconds on a
19 page document.
Public Sub TabsForPctAndCount()
Dim aRange As Word.Range
Dim oTable As Word.Table
Dim oCell As Cell
Dim UseableWidth As Single
Set aRange = ActiveDocument.Range(0, 0)
System.Cursor = wdCursorWait ' Displays the hourglass
StatusBar = "Defining tab positions in tables ..."
'Insert right aligning tab positions at 40% and 100% of each cell
For Each oTable In ActiveDocument.Tables
For Each oCell In oTable.Range.Cells
UseableWidth = oCell.Width - oCell.LeftPadding -
oCell.RightPadding
oCell.Range.ParagraphFormat.TabStops.ClearAll
oCell.Range.ParagraphFormat.TabStops.add
Position:=UseableWidth * 0.4, Alignment:=wdAlignTabRight
oCell.Range.ParagraphFormat.TabStops.add
Position:=UseableWidth, Alignment:=wdAlignTabRight
Next oCell
Next oTable
StatusBar = "Inserting tabs between percentages and counts ..."
'Replace a "XX.X% (" by "\tXX.X%\t("
With aRange.find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9.]@%)[ ]@\("
.Replacement.Text = "^t\1^t("
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With
System.Cursor = wdCursorNormal ' Normal cursor
StatusBar = "Macro TabsForPctAndCount completed."
End Sub
Thanks for any help,
John Hendrickx