[英]Adding slide titles in Powerpoint from an Excel file
我試圖從excel文件中的ppt添加幻燈片標題。 但我無法把它放在一個循環中。 從A1到A7的每個單元格在文件中都有幻燈片標題,因此我想根據幻燈片編號將標題放在幻燈片中。 下面是我寫的代碼。
For i = 1 To 7
With Application.Presentations(1)
For Each ppSlide In .Slides()
If ppSlide.Shapes.HasTitle Then ppSlide.Shapes.Title.TextFrame.TextRange = xlWorkSheet.Cells(i, 1)
Next ppSlide
End With
Next i
我假設你在PowerPoint中運行VBA代碼。
如果找到包含標題的對應形狀,則只能設置幻燈片標題。 可以通過Shape.Type = msoPlaceholder
和PlaceholderFormat.Type = ppPlaceholderTitle
(或PlaceholderFormat.Type = ppPlaceholderCenterTitle
)識別此形狀。
如果你想要從1到7的循環,那么你也可以通過索引從1到7來處理幻燈片(而不是通過所有幻燈片上的額外For Each
循環)。
Private Sub SetTitlesFromExcellist()
Dim xlApp As Excel.Application
Dim xlWorkSheet As Excel.worksheet
Dim ppSlide As PowerPoint.Slide
Dim ppShape As PowerPoint.Shape
Dim i As Long
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
On Error GoTo 0
If xlApp Is Nothing Then Exit Sub
Set xlWorkSheet = xlApp.ActiveSheet
For i = 1 To 7
Set ppSlide = ActivePresentation.Slides(i)
If ppSlide.Shapes.HasTitle Then
For Each ppShape In ppSlide.Shapes
If ppShape.Type = msoPlaceholder Then
Select Case ppShape.PlaceholderFormat.Type
Case ppPlaceholderCenterTitle, ppPlaceholderTitle
ppShape.TextFrame.TextRange.Text = xlWorkSheet.Cells(i, 1)
Exit For
End Select
End If
Next ppShape
End If
Next i
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.