2014-10-30 124 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