|
也可试试如下代码,自行指定关键词,希望对学习《民法典》有点帮助。- Sub test()
- '仅用于删除民法典中不含特定关键词的条文
- '文本要求:各编章节号及法条后应有空格(全半角不限),附则标题没空格,其他段落不能有空格
- Dim i As Integer '统计有两款及以上内容的法条数
- Dim n As Integer '统计含有指定关键词的法条数
- Dim keyword As String
-
- keyword = InputBox("处理后仅保留目录、章节名和包含关键词的条文!", "请输入要标记的关键词", "另有约定")
- If keyword = Empty Then Exit Sub
- Application.ScreenUpdating = False
- With ActiveDocument.Content.Find
- .Text = "^13第[!^13条]{1,7}条[ ]"
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- If .End < ActiveDocument.Content.Paragraphs.Last.Previous.Range.Start Then
- Do While InStr(.Next(wdParagraph, 1).Text, " ") = 0 And InStr(.Next(wdParagraph, 1).Text, " ") = 0 _
- And .Next(wdParagraph, 1).Text Like "附则*" = False
- .End = .Next(wdParagraph).End
- Loop
- End If
- If .Paragraphs.Count > 2 Then i = i + 1 Else .MoveEnd wdParagraph
- If InStr(.Text, keyword) = 0 Then
- ActiveDocument.Range(.Start + 1, .End).Delete
- ' .SetRange .End - 1, .End - 1 '不想删除不含指定关键词的法条时用本行,并去掉上一行
- Else
- .HighlightColorIndex = wdYellow '突出显示含关键词的法条
- .Start = .End - 1
- n = n + 1
- End If
- .Collapse wdCollapseStart
- End With
- Loop
- '以下三行可用于删除民法典中各级标题
- ' .Parent.WholeStory
- ' .Execute findtext:="第[!编章节条]{1,3}[编章节][ ]*^13", replacewith:="", Replace:=wdReplaceAll
- ' .Execute findtext:="附则^13", replacewith:="", Replace:=wdReplaceOne
- End With
- MsgBox "共找到" & n & "个法条含有如下指定的关键词:" & keyword
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|