我想根据用户输入删除单词doc的整个部分/段落。
该文件包含" 1.1"和" 1.1.1"和" 1.2"用户将输入" 1.1.1"和宏将删除该部分。是否可以进行宏搜索" 1.1.1"并删除从1.1.1开始的所有内容,但不包括1.2?
我从这开始,但需要创建一个开始和结束点来删除。
Sub DeleteParagraphContainingString()
Dim search As String
search = "1.1.1"
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
Dim txt As String
txt = para.Range.Text
If InStr(LCase(txt), search) Then
para.Range.Delete
End If
Next
End Sub
答案 0 :(得分:0)
您可以使用Word的Find
功能,然后选择整个部分并将其删除。我给你一些代码片段,你可以编织在一起,应用检查,等等:
ActiveDocument.Range(0, 0).Select ' go to beginning of document
Selection.Find.ClearFormatting
With Selection.Find
.text = yourFindString
.Replacement.text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
While (Selection.Find.Execute)
Selection.Bookmarks("\HeadingLevel").Select ' select whole Section
title = Selection.Paragraphs(1).Range.text ' get Section Title (text of first paragraph)
Selection.Delete
Wend
我希望这会有所帮助。