如何从文档中的特定位置向下搜索并结束搜索?

huangapple go评论90阅读模式
英文:

How to search from a certain point in a document down and end the search?

问题

我有以下代码,用于在文档中搜索特定点并创建搜索范围,直到文档的末尾。然后在该范围内,删除完全是粗体段落(子标题)之后的段落,忽略任何不是“正文”样式且不在表格中的样式。然而,它似乎搜索整个文档(即开头也搜索)。如何让它只搜索范围(即从我放置光标的位置到文档末尾)?

Dim aPara As Paragraph
Dim oSearchRange As Range

With Selection.Find
    .Text = "Dear "
End With
Selection.MoveDown Unit:=wdParagraph, Count:=4

Set oSearchRange = Selection.Range
oSearchRange.End = ActiveDocument.Content.End

oSearchRange.MoveEnd wdParagraph, -1

For Each aPara In oSearchRange.Paragraphs
    If aPara.Range.Font.Bold = True And aPara.Range.Next.Style = ActiveDocument.Styles("Normal") And Not aPara.Range.Next.Information(wdWithInTable) Then aPara.Range.Next.Delete
Next aPara

谢谢。

英文:

I have the following code that searches for a certain point in a document and creates a search range until the end of the document. Then within that range it removes the paragraph following entirely bold paragraphs (subheadings), ignoring any styles that aren't Normal and aren't in a table. However, it seems to search the entire document (i.e. the beginning as well). How can I make it only search the range (i.e. from where I've positioned the cursor down to the end of the document)?

Dim aPara As Paragraph
Dim oSearchRange As Range

With Selection.Find
    .Text = "Dear "
End With
Selection.MoveDown Unit:=wdParagraph, Count:=4

Set oSearchRange = Selection.Range
oSearchRange.End = ActiveDocument.Content.End

oSearchRange.MoveEnd wdParagraph, -1

For Each aPara In oSearchRange.Paragraphs
    If aPara.Range.Font.Bold = True And aPara.Range.Next.Style = ActiveDocument.Styles("Normal") And Not aPara.Range.Next.Information(wdWithInTable) Then aPara.Range.Next.Delete
Next aPara

Thanks

答案1

得分: 0

我需要在“亲爱的”搜索后添加 .Execute,感谢 Teamothy (:

英文:

I needed to add .Execute after the "Dear " search, thanks to Teamothy (:

huangapple
  • 本文由 发表于 2020年1月3日 17:50:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576339.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定