如何创建许多幻灯片,其中包含来自 Excel table 的变量的幻灯片?
How to create many powerpoint presentations containing a slide with a variable from an Excel table?
我正在尝试使用 Excel table.
中的值创建 PowerPoint 演示文稿
A2、A3、A4 等各包含一个名称。每个 pptx 文件中的幻灯片将是一个包含三个段落的测试,并且在开始时这些单元格中的名称是这样处理的:
Dear 'BA2',
[paragraph1 ]
[paragraph 2]
Yours faithfully,
...
其他单元格也是如此。
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
此代码会将整个 table 复制并粘贴到一张幻灯片中。与我想要的完全不同,但我需要知道的是如何使用 for 循环或类似的东西将这些单元格逐个粘贴到单独的工作表中。
转到母版幻灯片视图并根据需要制作模板;例如特定的文本框和其他东西,然后从 excel 每次制作该模板的新幻灯片,并从单元格中的变量填充这些框。如果您只是在学习编程,那比尝试通过代码添加文本框和所有内容要好。
for循环上的代码取决于你的演示幻灯片结构,如果你能指定数据和格式,那么就很清楚了。
将此代码放入 powerpoint VBA,它会让你访问 excel 中的数据,打开 excel sheet 数据,然后 运行循环中适当的东西。
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
我正在尝试使用 Excel table.
中的值创建 PowerPoint 演示文稿A2、A3、A4 等各包含一个名称。每个 pptx 文件中的幻灯片将是一个包含三个段落的测试,并且在开始时这些单元格中的名称是这样处理的:
Dear 'BA2',
[paragraph1 ]
[paragraph 2]
Yours faithfully,
...
其他单元格也是如此。
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
此代码会将整个 table 复制并粘贴到一张幻灯片中。与我想要的完全不同,但我需要知道的是如何使用 for 循环或类似的东西将这些单元格逐个粘贴到单独的工作表中。
转到母版幻灯片视图并根据需要制作模板;例如特定的文本框和其他东西,然后从 excel 每次制作该模板的新幻灯片,并从单元格中的变量填充这些框。如果您只是在学习编程,那比尝试通过代码添加文本框和所有内容要好。 for循环上的代码取决于你的演示幻灯片结构,如果你能指定数据和格式,那么就很清楚了。 将此代码放入 powerpoint VBA,它会让你访问 excel 中的数据,打开 excel sheet 数据,然后 运行循环中适当的东西。
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