簡體   English   中英

Powerpoint VBA - 如何將文本框添加到多張幻燈片

[英]Powerpoint VBA - How to add text box to multiple slides

因此,我使用以下代碼將文本框添加到幾張幻燈片的 header 中:

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

當我運行此代碼時,我收到一個自動化錯誤並且它不起作用。 如果我在一張幻燈片上這樣做,它確實有效。 有誰知道為什么? 我試圖做的是將標題添加到特定幻燈片。 所以我將使用相同的方法為其他幻燈片添加不同的標題。

幻燈片沒有標題。 但這里的代碼可以工作:

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

您可以通過所有幻燈片 go 使用您設置的數組中的數字:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM