2014-10-30 31 views
1

我有一個大的PPT文件,需要根據特定規格進行格式化。除非文字加下劃線,否則我需要所有字體都是Arial 14。如果文本加下劃線,我需要的字體是32.這是我迄今爲止的嘗試,我有Arial 14部分工作,但我無法弄清楚如何選擇下劃線的文本。如果任何人有任何想法,將不勝感激。我也有VBA零經驗這個項目之外,儘管我熟悉C++在Powerpoint中更改帶下劃線的文本字體

Sub use() 
Dim s As Slide 
Dim shp As Shape 

For Each s In ActivePresentation.Slides 
For Each shp In s.Shapes 
    If shp.HasTextFrame Then 
     With shp 
     .TextFrame.TextRange.Font.Name = "Arial" 
     .TextFrame.TextRange.Font.Size = 14 
      If .TextFrame.TextRange.Font.Underline = True Then 
       .TextFrame.TextRange.Font.Size = 32 
      End If 
      With .TextFrame.TextRange 
      .ParagraphFormat.SpaceBefore = 0 
      End With 

     End With 

     End If 
    Next shp 
Next s 
End Sub 

回答

1

試試這個

Sub Sample() 
    Dim oSl As Slide 
    Dim oSh As Shape 
    Dim x As Long 

    For Each oSl In ActivePresentation.Slides 
     For Each oSh In oSl.Shapes 
      If oSh.HasTextFrame Then 
       If oSh.TextFrame.HasText Then 
        For x = 1 To Len(oSh.TextFrame.TextRange.Text) 
         If oSh.TextFrame.TextRange.Characters(x, 1).Font.Underline = True Then 
          With oSh.TextFrame.TextRange.Characters(x, 1) 
           .Font.Size = 32 
          End With 
         End If 
        Next 
       End If 
      End If 
     Next 
    Next 
End Sub 

截圖

enter image description here