P
Peter
Hello,
I have been trying to speed up a macro I am using to loop through fields. It
was taking over 3 hours to run (this on a dual-core E6600 with 2GB ram) so I
thought I'd troubleshoot and figure out where the bottlenecks are. I've
truncated all the code and left only the loop through the fields. Here is the
code:
Sub TraceMatXref()
Dim reqRange As Range, aField As Field, sw As StopWatch
If ActiveDocument.Bookmarks.Exists("myRange") Then
Set reqRange = ActiveDocument.Bookmarks("myRange").Range
Set sw = New StopWatch
sw.StartTimer
For Each aField In reqRange.Fields
Next aField
Debug.Print "Elapsed time:= " & sw.EndTimer
End If
End Sub
Stopwatch is a routine I got from the "VBA Developer's Handbook" by Getz &
Gilbert.
Anyway, there are only 375 fields in the range and yet it takes almost three
hours to run through this code! If I move the timer inside the loop, the
stopwatch function reports 0 time for each loop but the time between
iterations slows to a crawl as each loop is executed.
Anybody got any ideas what is going on here?
Thanks,
Peter
I have been trying to speed up a macro I am using to loop through fields. It
was taking over 3 hours to run (this on a dual-core E6600 with 2GB ram) so I
thought I'd troubleshoot and figure out where the bottlenecks are. I've
truncated all the code and left only the loop through the fields. Here is the
code:
Sub TraceMatXref()
Dim reqRange As Range, aField As Field, sw As StopWatch
If ActiveDocument.Bookmarks.Exists("myRange") Then
Set reqRange = ActiveDocument.Bookmarks("myRange").Range
Set sw = New StopWatch
sw.StartTimer
For Each aField In reqRange.Fields
Next aField
Debug.Print "Elapsed time:= " & sw.EndTimer
End If
End Sub
Stopwatch is a routine I got from the "VBA Developer's Handbook" by Getz &
Gilbert.
Anyway, there are only 375 fields in the range and yet it takes almost three
hours to run through this code! If I move the timer inside the loop, the
stopwatch function reports 0 time for each loop but the time between
iterations slows to a crawl as each loop is executed.
Anybody got any ideas what is going on here?
Thanks,
Peter