|
楼主 |
发表于 2024-9-23 13:43
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
谢谢高手,我修改到以下效果了,代码在图下面。如何继续修改代码,删除ppt中的标题文本框,让正文文本框最大化适应ppt页面,并让ppt中的表格按照文字长短自动调整列宽,
Const ppLayoutTitle = 1
Const ppLayoutText = 2
Sub ExcelToPPT()
Dim data_array As Variant
Dim lstRow As Integer
Dim slides_count As Integer
Dim objPPT As Object
Dim objPresentation As Object
Dim pptSlide As Object
Dim objTbl As Object
Dim lRow As Byte
Dim lCol As Byte
Dim i As Integer
With Sheet1
lstRow = .Range("D1048576").End(xlUp).Row ' 假设数据直到列D
data_array = .Range("A1").Resize(lstRow, 4).Value ' 读取A、B、C、D四列数据
End With
slides_count = Application.Ceiling(lstRow / 7, 1)
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Set objPresentation = objPPT.Presentations.Add
With objPresentation
.Slides.Add Index:=1, Layout:=ppLayoutTitle
For i = 1 To slides_count
Set pptSlide = .Slides.Add(i, ppLayoutText)
Set tbl = pptSlide.Shapes.AddTable(7, 4, 65, 145, 830, 310) ' 创建4列的表格
Set objTbl = pptSlide.Shapes(3).Table
With objTbl
For lRow = 1 To 7
startRow = (i - 1) * 7 + lRow
If startRow <= lstRow Then
For lCol = 1 To 4 ' 遍历4列
With .cell(lRow, lCol).Shape.TextFrame.TextRange
.Font.Name = "Tahoma(Body)"
.Font.Size = 32
.Font.Color = RGB(64, 65, 70)
.Text = data_array(startRow, lCol)
End With
Next
End If
Next
End With
Next i
.SaveAs ThisWorkbook.Path & "\Sample.pptx"
End With
End Sub
|
|