繁体   English   中英

如何搜索多个字符串并更改字体颜色

[英]How to search for multiple strings and change font color

我需要在幻灯片文本框中搜索多个字符串并更改段落的颜色。 例如,如果段落以“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

您不想为每个条件创建额外的代码,请使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM