[英]How to search for multiple strings and change font color
I need to search for multiple strings in slide text boxes and change the color of the paragraph.我需要在幻灯片文本框中搜索多个字符串并更改段落的颜色。 For example if the paragraph starts with "A."例如,如果段落以“A”开头。 or "1."或“1”。 or "Z."或“Z”。 -- then I want to turn the paragraph bold. -- 然后我想把段落加粗。
I can setup individual searches ---but is there a way to search for all three criteria at the same time?我可以设置单独的搜索---但是有没有办法同时搜索所有三个条件?
Here are the individual searches:以下是个人搜索:
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
You don't want to create additional code for each criteria, use a Case
statement您不想为每个条件创建额外的代码,请使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.