删除包含特定单词的段落(单词vba) [英] Remove Paragraph Containg specific words(word vba)

查看:118
本文介绍了删除包含特定单词的段落(单词vba)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉没有程序可以显示我的问题,但是我很生气.

I apologize for not having a program to show for my question, but I am in a serious pickle.

我正在寻找一个vba单词程序,该程序可搜索特定单词并删除这些单词所在的段落.

I am looking for a vba word program that searches for specific words and deletes the paragraph those words are in.

此练习的目的是减少工作量,因为我正在使用多达一百万个文字的单词.

The aim of this exercise is to reduce the work load as I am using up to 1million plus words of text.

编辑

我已经创建了程序,请您帮我添加一个循环,循环遍历整个文档吗?

I have created the program, could you please help me add a loop, to loop through the whole document?

Sub SelectRangeBetween()


    Selection.HomeKey Unit:=wdStory
    'Selection.TypeText Text:="hello"

     ' The Real script
    Dim myrange As Range
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        .Execute findtext:="From: Research.TA@traditionanalytics.com", Forward:=True, Wrap:=wdFindStop 'this will initiate the start word
        Set myrange = Selection.Range
        myrange.End = ActiveDocument.Range.End
        myrange.Start = myrange.Start
        myrange.End = myrange.End + InStr(myrange, "This message has been scanned ") ' this will initiate the end word
        myrange.Select

        'Selection.Delete
    End With
End Sub

推荐答案

尝试以下操作,它将搜索 TextToSearchFor 并删除放置代码的同一文档中的段落. (因为我使用了ThisDocument对象).由于您没有在问题中指定许多详细信息,因此必须修改TryMe子项以适合您的需求.确保首先在测试文档上尝试! :)

Try the following, it will search for TextToSearchFor and delete the paragraphs where it is found in the same document where you place the code (because I use the ThisDocument object). Since you do not specify many details in your question, you will have to modify the TryMe sub to fit your needs. Make sure you try it on a test document first! :)

Option Explicit

Sub TryMe()
    Call RemoveParagraphs("TextToSearchFor")
End Sub

Sub RemoveParagraphs(psSearchString As String)
    Dim oRng As Range

    Set oRng = ThisDocument.Content

    oRng.Find.Execute FindText:=psSearchString

    While oRng.Find.Found
        oRng.Select
        Selection.Expand Unit:=wdParagraph
        Selection.Delete

        Set oRng = ThisDocument.Content
        oRng.Find.Execute FindText:=psSearchString
    Wend

End Sub

这篇关于删除包含特定单词的段落(单词vba)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆