![](/img/trans.png)
[英]How to create a title on a powerpoint slide using 2 cells from an excel spreadsheet
[英]How to create many powerpoint presentations containing a slide with a variable from an Excel table?
我正在嘗試使用 Excel 表格中的值創建 PowerPoint 演示文稿。
A2、A3、A4 等將分別包含一個名稱。 每個 pptx 文件中的幻燈片將是一個包含三個段落的測試,並且在開頭這些單元格中的名稱以這種方式尋址:
親愛的“BA2”,
[第1段]
[第2段]
此致,
...
其他細胞也是如此。
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dm ppSlide As PowerPoint.Slide
Set ppApp = New PowerPoint.Application
ppApp.Visible = True
ppApp.Activate
Set ppPres = ppApp.Presentations.Add
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
Set ppApp = New PowerPoint.Application
ppApp.Visible = True
ppApp.Activate
set ppSlide = ppPres.Slides.Add(2,pp LayoutBlank(
ppSlide.Select
Range("A1").CurrentRegion.Copy
ppSlide.Shapes.Paste
此代碼會將整個表格復制並粘貼到一張幻燈片中。 與我想要的完全不同,但我需要知道的是如何使用 for 循環或類似的東西將這些單元格逐個粘貼到單獨的工作表中。
轉到母版幻燈片視圖並根據需要制作模板; 像特定的文本框和東西,然后從 excel 每次制作該模板的新幻燈片,並從單元格中的變量填充這些框。 如果您只是在學習編程,那比嘗試通過代碼添加文本框和所有內容要好。 for 循環上的代碼取決於你的演示幻燈片結構,如果你能指定數據和格式,那就很清楚了。 將此代碼放在powerpoint VBA中,它可以讓您訪問excel中的數據,打開帶有數據的excel表並在循環中放入適當的內容后運行它。
Public Sub test()
Dim excelSht As Worksheet
Dim excelApp As Excel.Application
Set excelApp = GetObject(, "excel.application")
Set excelSht = excelApp.ActiveSheet
Dim path As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
path = .SelectedItems(1)
End With
'Set rng = excelApp.Selection ' use this if you want to select the data in advance
Set rng = excelSht.Range("A2:A140") ' use this if your data range is fixed
For Each cel In rng
For Each shp In Application.Presentations(1).Slides(1).Shapes
If shp.Name Like "Title 1" Then shp.TextFrame.TextRange.Text = "Dear, " & cel.Value ' this one choose the name of the shape of which one you want to change the text.
Next
Application.Presentations(1).SaveAs (path & "\" & cel.Value & ".pptx")
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.