我有一个代码,我想循环遍历整个文档,检查它是否以数字开头,如果是,则添加一个段落。
但是,它不会计算循环中的新段落,因此直到文档结束时才会执行。
Sub test()
lastpar = ActiveDocument.Paragraphs.Count
For i = 1 To lastpar
If IsNumeric(ActiveDocument.Paragraphs(i).Range.Words(1).Characters(1)) = True Then
If ActiveDocument.Paragraphs(i + 1).Range.Characters.Count > 1 Then
ActiveDocument.Paragraphs(i).Range.Paragraphs.Add
lastpar = lastpar + 1
End If
End If
Next i
End Sub如您所见,我尝试将lastpar = lastpar + 1添加到代码中,但仍然不起作用。
发布于 2017-07-14 23:47:02
通过添加While i < lastpar使其正常工作
Sub test()
lastpar = ActiveDocument.Paragraphs.Count
While i < lastpar
For i = 1 To lastpar
If IsNumeric(ActiveDocument.Paragraphs(i).Range.Words(1).Characters(1)) = True Then
If ActiveDocument.Paragraphs(i + 1).Range.Characters.Count > 1 Then
ActiveDocument.Paragraphs(i).Range.Paragraphs.Add
lastpar = lastpar + 1
End If
End If
Next i
Wend
End Subhttps://stackoverflow.com/questions/45085376
复制相似问题