简体   繁体   中英

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." or "1." or "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

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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