删除特定数量的文本,直到找到打开的段落

发布于 2025-01-04 23:27:28 字数 249 浏览 4 评论 0原文

我正在创建一个宏,允许我删除特定数量的文本,直到找到一个打开的段落。例如:

gateways (...)
ABC
DEF
GHJ
IKL

Other

我想通过搜索“gateways”一词来删除,然后删除所有文本,直到找到“Other”之前的行。问题是,“其他”之前的文本量因文档而异,并且我找不到允许我在没有错误的情况下执行此操作的宏。

I am looking to create a macro that allows me to delete a specific amount of text until it finds an open paragraph. For example:

gateways (...)
ABC
DEF
GHJ
IKL

Other

I want to delete by searching the word "gateways" and then delete all text until it finds the line before "Other". The problem is that the amount of text until "other" is variable from document to document, and I cannot find a macro that allows me to do that wothout errors.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜爱纠缠 2025-01-11 23:27:28

将文本“网关”删除到空行,仅保留“其他”

Public Sub DeleteFromTextToEmptyLine()
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "gateways"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    'find text
    If Selection.Find.Execute() Then
        'Selection.Collapse wdCollapseEnd 'remove comment to leave the word gateway intact
        'Turn on Extended select mode
        Selection.ExtendMode = True
        'find two paragraph marks together, i.e. empty line
        With Selection.Find
            .Text = "^p^p"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        'if found, delete the selection
        If Selection.Find.Execute() Then Selection.Delete
    End If
End Sub

如果要保留“网关”一词,请从指示的行中删除注释

To delete the text Gateway down to the empty line, leaving only Other

Public Sub DeleteFromTextToEmptyLine()
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "gateways"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    'find text
    If Selection.Find.Execute() Then
        'Selection.Collapse wdCollapseEnd 'remove comment to leave the word gateway intact
        'Turn on Extended select mode
        Selection.ExtendMode = True
        'find two paragraph marks together, i.e. empty line
        With Selection.Find
            .Text = "^p^p"
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        'if found, delete the selection
        If Selection.Find.Execute() Then Selection.Delete
    End If
End Sub

If you want to leave the word gateway, remove the comment from the indicated line

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文