A
Andrew V
Good day,
I have a macro that at some point has to edit text in a TOC. For some
reason simply using ranges to edit the TOC body is *much* slower than using
Selection. This:
If myTOC.Range.Find.Execute("00000") Then
For Each para In myTOC.Range.Paragraphs
If InStr(1, para.Range.Text, "00000") <> 0 Then
para.Range.ParagraphFormat.TabStops.ClearAll
End If
Next para
End If
is slower by half than this:
myTOC.Range.Select
If Selection.Find.Execute("00000") Then
Selection.ParagraphFormat.TabStops.ClearAll
mypara = Selection.Information(wdFirstCharacterLineNumber)
mypage = Selection.Information(wdActiveEndPageNumber)
mysec = Selection.Information(wdActiveEndSectionNumber)
While Selection.Find.Execute("00000") And
Selection.Information(wdActiveEndSectionNumber) = mysec _
And (Selection.Information(wdActiveEndPageNumber) > mypage _
Or Selection.Information(wdFirstCharacterLineNumber) > mypara)
Selection.ParagraphFormat.TabStops.ClearAll
Wend
End If
I would have thought the first is faster, simpler and altogether preferred,
but any ideas why it takes over twice as long to execute?
Thanks,
Andrew
I have a macro that at some point has to edit text in a TOC. For some
reason simply using ranges to edit the TOC body is *much* slower than using
Selection. This:
If myTOC.Range.Find.Execute("00000") Then
For Each para In myTOC.Range.Paragraphs
If InStr(1, para.Range.Text, "00000") <> 0 Then
para.Range.ParagraphFormat.TabStops.ClearAll
End If
Next para
End If
is slower by half than this:
myTOC.Range.Select
If Selection.Find.Execute("00000") Then
Selection.ParagraphFormat.TabStops.ClearAll
mypara = Selection.Information(wdFirstCharacterLineNumber)
mypage = Selection.Information(wdActiveEndPageNumber)
mysec = Selection.Information(wdActiveEndSectionNumber)
While Selection.Find.Execute("00000") And
Selection.Information(wdActiveEndSectionNumber) = mysec _
And (Selection.Information(wdActiveEndPageNumber) > mypage _
Or Selection.Information(wdFirstCharacterLineNumber) > mypara)
Selection.ParagraphFormat.TabStops.ClearAll
Wend
End If
I would have thought the first is faster, simpler and altogether preferred,
but any ideas why it takes over twice as long to execute?
Thanks,
Andrew