|
增加了包含表格的判断,为什么正则没执行,帮忙看下?谢谢。
Sub PptRegexMatch2() '正则查找/替换-----把文中“#$”两个符号之间的内容变成黄色,ppt2010版通过,ppt2003版分段后有问题
' 好吧,你打开PowerPoint的查找/替换,就知道有多坑!!!
' 好吧,用VBScript的正则功能来弥补,来增强
' 正则可以自拟,参考:http://msdn.microsoft.com/en-us/library/ms974570.aspx
' 颜色值亦可自拟。。。
Dim oSld As Slide, oShp As Shape
Dim lRGB As Long
Dim strPattern As String
Dim oRange As TextRange
Dim i As Integer, iPos As Integer, iLen As Integer
' 正则相关变量
Dim regx As Object
Dim oMatch As Object
Dim oRow As Row
' 这里写颜色值
lRGB = RGB(255, 255, 0)
' 这里写查找的正则
'strPattern = "【(例\d+.*?|答案|考点|解析)】"
strPattern = "(\#.*?\$)" '"\#.*?\$"
Set regx = CreateObject("vbscript.regexp")
With regx
.Global = True
.IgnoreCase = True
.Pattern = strPattern
End With
For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
If oShp.HasTable Then
For Each oRow In oShp.Table.Rows
For j = 1 To oRow.Cells.Count
If oRow.Cells(j).Shape.TextFrame.HasText Then
Set oRange = oRow.Cells(j).Shape.TextFrame.TextRange
With oRow.Cells(j).Shape.TextFrame.TextRange
If (regx.test(.Text) = True) Then '为什么这个判断执行不了?
Set oMatch = regx.Execute(.Text)
For i = 0 To oMatch.Count - 1
iPos = oMatch(i).Firstindex
iLen = oMatch(i).Length
oRange.Characters(iPos + 2, iLen - 2).Font.Color.RGB = lRGB
Next i
End If
End With
End If
Next j
Next
End If
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
Set oRange = oShp.TextFrame.TextRange
With oShp.TextFrame.TextRange
If (regx.test(.Text) = True) Then
Set oMatch = regx.Execute(.Text)
For i = 0 To oMatch.Count - 1
iPos = oMatch(i).Firstindex
iLen = oMatch(i).Length
oRange.Characters(iPos + 2, iLen - 2).Font.Color.RGB = lRGB
Next i
End If
End With
End If
End If
Next oShp
Next oSld
Set regx = Nothing
End Sub |
|