|
楼主 |
发表于 2017-12-27 09:54
|
显示全部楼层
琢磨了两天,终于弄懂一点点,按关键字改变所在“行”颜色的,加个循环搞掂:
- Private Sub CommandButton2_Click()
- Dim r%, i%, j%, k%, Mh, kr
- Dim arr, brr
- Dim reg As New RegExp
- 'On Error Resume Next
- Application.ScreenUpdating = False
- kr = Array("参数", "警告") '
- With reg
- .Global = True
- .Pattern = ".+?(\n|$)"
- End With
- With Worksheets("关键字")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- For i = 1 To r
- Set Mh = reg.Execute(.Cells(i, 2).Value)
- With .Cells(i, 2)
- .Font.ColorIndex = 0
- For j = 0 To Mh.Count - 1
- For k = 0 To UBound(kr)
- If InStr(Mh(j), kr(k)) Then
- With .Characters(Start:=Mh(j).firstindex, Length:=Mh(j).Length + 1).Font
- .ColorIndex = 3
- End With
- End If
- Next
- Next
- End With
- Next
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
正则还是未了解透彻,本想用字符串元素数组的方法处理,但没成功 |
|