C
ckxplus
Back in June, I posted a problem on this newsgroup about as macro that
searches for a regular pattern in table cells and defines tab
positions if the pattern is found (Thread 'find, format tabs and
replace in table cells'). Thanks to Helmut Weber, my initial attempt
was greatly improved and worked at an acceptable speed in Word 2000
(from 25 seconds on a 19 page document to .375 seconds!).
But now I've got Word 2003 and I'm also working on larger documents
(60 pages) and processing time has increased to 6 minutes. I suspect
that memory problems are playing up as well since another macro
creates garbage if run after this first one, whereas it runs perfectly
if I save and quit Word before running it. Does anyone have any
suggestions on how to improve the performance of this macro?
(From my posting on June 27: 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.)
Advance thanks for any help,
John Hendrickx
Public Sub TabsForPctAndCount()
Dim t As Single
t = Timer
Dim aRange As Range
Dim oCell As Cell
Dim UseableWidth As Single
Set aRange = ActiveDocument.Range
System.Cursor = wdCursorWait ' Displays the hourglass
Application.ScreenUpdating = False
With aRange.find
.Text = "([0-9.]{1,8}%)[ ]{1,5}\("
.Replacement.Text = "^t\1^t("
.MatchWildcards = True
While .Execute
If aRange.Information(wdWithInTable) Then
.Execute replace:=wdReplaceOne
Set oCell = aRange.Cells(1)
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
aRange.Start = oCell.Range.End + 1
aRange.End = ActiveDocument.Range.End
End If
Wend
End With
System.Cursor = wdCursorNormal ' Normal cursor
Application.ScreenUpdating = True
StatusBar = "Macro TabsForPctAndCount completed."
MsgBox Timer - t
End Sub
searches for a regular pattern in table cells and defines tab
positions if the pattern is found (Thread 'find, format tabs and
replace in table cells'). Thanks to Helmut Weber, my initial attempt
was greatly improved and worked at an acceptable speed in Word 2000
(from 25 seconds on a 19 page document to .375 seconds!).
But now I've got Word 2003 and I'm also working on larger documents
(60 pages) and processing time has increased to 6 minutes. I suspect
that memory problems are playing up as well since another macro
creates garbage if run after this first one, whereas it runs perfectly
if I save and quit Word before running it. Does anyone have any
suggestions on how to improve the performance of this macro?
(From my posting on June 27: 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.)
Advance thanks for any help,
John Hendrickx
Public Sub TabsForPctAndCount()
Dim t As Single
t = Timer
Dim aRange As Range
Dim oCell As Cell
Dim UseableWidth As Single
Set aRange = ActiveDocument.Range
System.Cursor = wdCursorWait ' Displays the hourglass
Application.ScreenUpdating = False
With aRange.find
.Text = "([0-9.]{1,8}%)[ ]{1,5}\("
.Replacement.Text = "^t\1^t("
.MatchWildcards = True
While .Execute
If aRange.Information(wdWithInTable) Then
.Execute replace:=wdReplaceOne
Set oCell = aRange.Cells(1)
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
aRange.Start = oCell.Range.End + 1
aRange.End = ActiveDocument.Range.End
End If
Wend
End With
System.Cursor = wdCursorNormal ' Normal cursor
Application.ScreenUpdating = True
StatusBar = "Macro TabsForPctAndCount completed."
MsgBox Timer - t
End Sub