|
楼主 |
发表于 2024-12-23 09:41
|
显示全部楼层
以下是代码文字版,哪位兄弟有空的话,可以帮试试看是什么问题。
- Sub A自动转换()
- Dim 段落 As Paragraph, 正 As Object, i As Byte, 字符 As Long, 范围 As Range, 内容 As Range
- Set 正 = CreateObject("vbscript.regexp")
- arr = Array("^\d+\.\d+[^\.0-9]", "^\d+\.\d+\.\d+[^\.0-9]", "^\d+\.\d+\.\d+\.\d+[^\.0-9]", "^\d+\.\d+\.\d+\.\d+\.\d+[^\.0-9]")
- brr = Array(wdStyleHeading2, wdStyleHeading3, wdStyleHeading4, wdStyleHeading5)
- '=========move方法 学习冬瓜老师的方法=========
- With Selection
- Set 内容 = IIf(.Type = wdSelectionIP Or .Type = wdNoSelection, ActiveDocument.Content, .Range)
- End With
- With ActiveDocument
- With .Range(内容.Start, 内容.Start)
- Do While .End < 内容.End - 1
- '=========跳过表格=========
- If .Information(12) Then
- .Expand 15: .Move
- Else
- Set 段落 = .Paragraphs(1)
- For i = LBound(arr) To UBound(arr)
- With 正
- .Pattern = arr(i): .Global = True
- .IgnoreCase = False: .MultiLine = True
- If .test(段落.Range.Text) Then
- 段落.Range.ParagraphFormat.Style = brr(i)
- '=========删除原来的编号=========
- Set match = .Execute(段落.Range.Text)(0)
- 字符 = Len(match)
- Set 范围 = 段落.Range
- 范围.SetRange 范围.Start, 范围.Start + 字符 - 1
- 范围.Delete
- End If
- End With
- Next
- End If
- .Move 4
- Loop
- End With
- End With
- End Sub
复制代码 |
|