我需要在幻灯片文本框中搜索多个字符串并更改段落的颜色。例如,如果段落以" A。"开头。或" 1。"或" Z。" - 然后我想把段落加粗。
我知道我可以设置个人搜索 - 但是有没有办法同时搜索所有三个条件?
以下是个人搜索:
For Each curShape In curSlide.Shapes
If curShape.TextFrame.HasText Then
Set curText = curShape.TextFrame.TextRange
With curText
For iPara = .Paragraphs.Count To 1 Step -1
If Left(.Paragraphs(iPara), 2) = "A. " Then
.Paragraphs(iPara).Font.Bold = True
End If
For iPara = .Paragraphs.Count To 1 Step -1
If Left(.Paragraphs(iPara), 2) = "1. " Then
.Paragraphs(iPara).Font.Bold = True
End If
Next
End With
要搜索的字符串数量会增加 - 所以我希望尽可能提高代码效率。
感谢您的帮助!
答案 0 :(得分:1)
您不想为每个条件创建其他代码,请使用Case
语句
For Each curShape In curSlide.Shapes
If curShape.TextFrame.HasText Then
Set curText = curShape.TextFrame.TextRange
With curText
For iPara = .Paragraphs.Count To 1 Step -1
Select Case Left(.Paragraphs(iPara), 2)
Case "A.", "1." '# Add additional cases separated by commas
.Paragraphs(iPara).Font.Bold = True
Case Else
'do nothing
End Select
Next
End With