我有以下部分代码,随着时间的推移会逐渐减慢执行速度。我的Word文档有200多页,大约12000个段落。在大约第3000段,可以说执行比开始慢几倍。
任何方式我都可以将速度保持在同一水平?也许迭代段落根本无法用于大文档?
Dim worddoc As Word.Document
Dim ParaCount as long, J as long, x as long
Dim RowData as string
With worddoc
ParaCount = .Paragraphs.Count
For J = 1 To ParaCount
RowData = .Paragraphs(J).Range.Text
x = x + 1
If x Mod 10 = 0 Then Application.StatusBar = x
Next ParaCount
End With
答案 0 :(得分:3)
这样的事情应该有效。我相信你已经有了它的工作,但对于后人来说,这里提到了For Each
方法。
Public Sub Iterate_Paragraphs()
Dim Paragraph As Word.Paragraph
For Each Paragraph In ActiveDocument.Paragraphs
Debug.Print Paragraph.Range.Text
Next
End Sub