我有以下代码可以删除整个文档中所有粗体段落之后的段落。如何修改它,使其仅影响某些文本,特别是从光标所处的某个点到文档末尾?谢谢
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
If para.Range.Font.Bold = True Then para.Next.Range.Delete
Next para
答案 0 :(得分:0)
要限制搜索范围,您需要将ActiveDocument
替换为要搜索的范围。每当您在Word中编写代码时,最好避免使用Selection
对象。使用Selection
在屏幕上四处移动光标,这意味着每次必须重新绘制屏幕。通过使用Range
对象可以避免这种情况。
Dim para As Paragraph
Dim searchRange As Range
'pick up the start of the range
Set searchRange = Selection.Range
'move the end of the range to the end of the document
searchRange.End = ActiveDocument.Content.End
For Each para In searchRange.Paragraphs
If para.Range.Font.Bold = True Then para.Next.Range.Delete
Next para