簡體   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