|
增加第2列,我这里没有问题
- Sub RegExpDemo()
- Dim strTxt As String
- Dim objRegEx As Object, objMatch As Object
- Dim objMH As Object, c As Range
- Set objRegEx = CreateObject("vbscript.regexp")
- objRegEx.Pattern = "(\/.+?\/)"
- objRegEx.Global = True
- objRegEx.MultiLine = True
- For Each col In Array(2, 4)
- Columns(col).Font.Underline = xlUnderlineStyleNone
- For Each c In Range(Cells(2, col), Cells(Rows.Count, col).End(xlUp))
- strTxt = c.Value
- Set objMatch = objRegEx.Execute(strTxt)
- If objMatch.Count > 0 Then
- For Each objMH In objMatch
- strKey = objMH.submatches(0)
- istart = VBA.InStr(1, strTxt, strKey)
- c.Characters(istart, Len(strKey)).Font.Underline = xlUnderlineStyleSingle
- c.Characters(Start:=istart + Len(strKey), Length:=0).Font.Underline = xlUnderlineStyleNone
- Next
- End If
- Next
- Next
- Set objMH = Nothing
- Set objMatch = Nothing
- Set objRegEx = Nothing
- End Sub
复制代码 |
|