【问题标题】:Powerpoint VBA - How to add text box to multiple slidesPowerpoint VBA - 如何将文本框添加到多张幻灯片
【发布时间】:2021-04-27 21:00:32
【问题描述】:

所以我使用以下代码在几张幻灯片的标题中添加一个文本框:

Set myDocument = ActivePresentation.Slides.Range(Array(4, 5, 6))
Set newTextBox = myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
    260, Top:=30, Width:=541.44, Height:=43.218)
    With newTextBox.TextFrame.TextRange
        .Text = "Test Text"
        .Font.Size = 17
        .Font.Name = "Arial"
End With

当我运行此代码时,我收到一个自动化错误并且它不起作用。如果我在一张幻灯片上这样做,它确实有效。有谁知道为什么?我试图做的是将标题添加到特定幻灯片。所以我将使用相同的方法为其他幻灯片添加不同的标题。

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

    您可以使用您设置的数组中的数字浏览所有幻灯片:

    Sub slideTextBoxes()
        For Each myDocument In ActivePresentation.Slides.Range(Array(4, 5, 6))
            Set newTextBox = myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
                260, Top:=30, Width:=541.44, Height:=43.218)
            With newTextBox.TextFrame.TextRange
                .Text = "Test Text"
                .Font.Size = 17
                .Font.Name = "Arial"
            End With
        Next
    End Sub
    

    【讨论】:

    • 完美!谢谢
    【解决方案2】:

    幻灯片没有标题。但这里的代码可以工作:

    Sub AddTextBoxes()
        Dim oSlide As Slide
        Dim oShape As Shape
    
        For Each oSlide In ActivePresentation.Slides
            If oSlide.SlideIndex = 4 Or oSlide.SlideIndex = 5 Or oSlide.SlideIndex = 6 Then
                Set oShape = oSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, Left:=260, Top:=30, Width:=541.44, Height:=43.218)
                With oShape.TextFrame.TextRange
                    .Text = "Test Text"
                    .Font.Size = 17
                    .Font.Name = "Arial"
                End With
            End If
        Next oSlide
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-27
      • 2015-07-26
      • 1970-01-01
      • 2020-10-14
      • 2021-01-21
      • 2022-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多