使用VBA插入PowerPoint标题的循环10幻灯片

发布于 2025-02-09 18:17:42 字数 970 浏览 2 评论 0原文

我在Stackoverflow中看到了此代码,该代码将标题插入一个幻灯片。

Sub add_title()

Dim shpCurrShape As Shape
Dim ppPres As Presentation

Set ppPres = ActivePresentation

With ActivePresentation.Slides.Range(Array(1, 2, 3, 4, 5))

    If Not .Shapes.HasTitle Then
        Set shpCurrShape = .Shapes.AddTitle
    Else
        Set shpCurrShape = .Shapes.Title
    End If

    With shpCurrShape
        With .TextFrame.TextRange
            '~~> Set text here
            .Text = "BLAH BLAH"
            '~~> Alignment
            .ParagraphFormat.Alignment = 1
            '~~> Working with font
            With .Font
                .Bold = msoTrue
                .Name = "Tw Cen MT"
                .Size = 24
                .Color = RGB(0, 0, 0)
            End With
        End With
    End With
End With
End Sub

我想为给定数量的幻灯片添加相同的幻灯片标题,例如前十幅幻灯片。

我知道可以通过循环进行选择,从而选择感兴趣的幻灯片范围。

另外,如何定义阵列以指示幻灯片20至30?

I saw this code in StackOverflow that inserts a title in one slide.

Sub add_title()

Dim shpCurrShape As Shape
Dim ppPres As Presentation

Set ppPres = ActivePresentation

With ActivePresentation.Slides.Range(Array(1, 2, 3, 4, 5))

    If Not .Shapes.HasTitle Then
        Set shpCurrShape = .Shapes.AddTitle
    Else
        Set shpCurrShape = .Shapes.Title
    End If

    With shpCurrShape
        With .TextFrame.TextRange
            '~~> Set text here
            .Text = "BLAH BLAH"
            '~~> Alignment
            .ParagraphFormat.Alignment = 1
            '~~> Working with font
            With .Font
                .Bold = msoTrue
                .Name = "Tw Cen MT"
                .Size = 24
                .Color = RGB(0, 0, 0)
            End With
        End With
    End With
End With
End Sub

I would like to add the same slide title for a given number of slides, for example, the first ten slides.

I understand it can be done with a loop, selecting the range of the slides of interest.

Also, how would I define the array for indicating slides 20 to 30?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2025-02-16 18:17:42

我将把幻灯片更改为其他子的决定,然后将add_title仅转到您希望更改的幻灯片。

Sub AddTitles()
    Dim i As Long
    For i = 20 to 30
        add_title i
    Next i
End Sub

Sub add_title(ByVal slideNumber As Long)
    Dim ppPres As Presentation
    Set ppPres = ActivePresentation

    With ppPres.Slides(slideNumber)
        Dim shpCurrShape As Shape
        If Not .Shapes.HasTitle Then
            Set shpCurrShape = .Shapes.AddTitle
        Else
            Set shpCurrShape = .Shapes.Title
        End If

        With shpCurrShape
            With .TextFrame.TextRange
                '~~> Set text here
                .Text = "BLAH BLAH"
                '~~> Alignment
                .ParagraphFormat.Alignment = 1
               '~~> Working with font
               With .Font
                  .Bold = msoTrue
                  .Name = "Tw Cen MT"
                  .Size = 24
                  .Color = RGB(0, 0, 0)
               End With
            End With
        End With
    End With
End Sub

I would move the decision over which slides to change to a different sub, then call add_title only to those slides you wish to change.

Sub AddTitles()
    Dim i As Long
    For i = 20 to 30
        add_title i
    Next i
End Sub

Sub add_title(ByVal slideNumber As Long)
    Dim ppPres As Presentation
    Set ppPres = ActivePresentation

    With ppPres.Slides(slideNumber)
        Dim shpCurrShape As Shape
        If Not .Shapes.HasTitle Then
            Set shpCurrShape = .Shapes.AddTitle
        Else
            Set shpCurrShape = .Shapes.Title
        End If

        With shpCurrShape
            With .TextFrame.TextRange
                '~~> Set text here
                .Text = "BLAH BLAH"
                '~~> Alignment
                .ParagraphFormat.Alignment = 1
               '~~> Working with font
               With .Font
                  .Bold = msoTrue
                  .Name = "Tw Cen MT"
                  .Size = 24
                  .Color = RGB(0, 0, 0)
               End With
            End With
        End With
    End With
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文