在Powerpoint中更改带下划线的文本字体

时间:2014-10-30 21:34:52

标签: vba powerpoint powerpoint-vba

我有一个大型PPT文件,我需要格式化为某些规格。除非文本带下划线,否则我需要所有字体都是Arial 14。如果文字有下划线,我需要字体为32.这是我到目前为止的尝试,我有Arial 14部分工作,但我无法弄清楚如何只选择带下划线的文本。如果有人有任何想法,将不胜感激。虽然我熟悉c ++

,但我对该项目之外的VBA也没有经验
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 个答案:

答案 0 :(得分: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