|
楼主 |
发表于 2022-12-11 15:43
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
问chatgpt3硬是把答案问出来了,已解决!
Sub 本单文档【解析】前缀题号vba()
''''''''真题集相对后段段首前缀前段题号111.【解析】
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13█([0-9])([0-9])([0-9]).【解析】"
.Replacement.Text = "^13【解析】"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13█([0-9])([0-9]).【解析】"
.Replacement.Text = "^13【解析】"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^13█([0-9]).【解析】"
.Replacement.Text = "^13【解析】"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Dim 定位词 As String
定位词 = "【解析】"
Dim 题号词 As String
题号词 = "█([0-9]{1,})."
Dim 本段 As Paragraph
For Each 本段 In ActiveDocument.Paragraphs '''''1遍历活动文档所有段落
If InStr(1, 本段.range.Text, 定位词) > 0 Then ''''2如果本段搜到定位词【解析】
If InStr(1, 本段.Previous.range.Text, 题号) > 0 Then ''''3如果本段搜到题号词【█111.】
本段.Previous.range.Select '''''''''4选择本段前一段
With Selection.Find '''''''''5搜索题号词
.Text = 题号词
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
If .Execute Then '''''''''6如果存在题号词
Selection.Copy '''''7复制题号词
本段.range.Select '''''8选择本段落
Selection.Move wdParagraph, -1 '''''9光标移动到段落头
本段.range.Collapse Direction:=wdCollapseStart ''''10光标移到本段
Selection.Paste ''''''11粘贴刚才的复制
End If
End With
End If
End If
Next 本段 ' ' ' ' '█8遍历下一个含词段落
End Sub
|
|