Vba 删除特定数量的文本,直到找到打开的段落
我希望创建一个宏,允许我删除特定数量的文本,直到它找到一个打开的段落。例如: 网关(…) 基础知识 DEF GHJ IKL 其他Vba 删除特定数量的文本,直到找到打开的段落,vba,text,ms-word,Vba,Text,Ms Word,我希望创建一个宏,允许我删除特定数量的文本,直到它找到一个打开的段落。例如: 网关(…) 基础知识 DEF GHJ IKL 其他 我想通过搜索单词“gateways”来删除,然后删除所有文本,直到找到“Other”之前的行。问题是在“其他”之前的文本量在文档之间是可变的,我找不到一个宏允许我在没有错误的情况下这样做。删除文本网关到空行,只留下其他文本 Public Sub DeleteFromTextToEmptyLine() Selection.Find.ClearFormattin
我想通过搜索单词“gateways”来删除,然后删除所有文本,直到找到“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
如果您想离开word gateway,请删除指示行中的注释您的“段落”在正则表达式中是否可以定义为“\n\n+”?