首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >增加新段落后更新.Paragraphs.Count变量

增加新段落后更新.Paragraphs.Count变量
EN

Stack Overflow用户
提问于 2017-07-13 23:38:34
回答 1查看 153关注 0票数 0

我有一个代码,我想循环遍历整个文档,检查它是否以数字开头,如果是,则添加一个段落。

但是,它不会计算循环中的新段落,因此直到文档结束时才会执行。

代码语言:javascript
复制
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添加到代码中,但仍然不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-14 23:47:02

通过添加While i < lastpar使其正常工作

代码语言:javascript
复制
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 Sub
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45085376

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档