将列中的Excel单元格复制到PowerPoint形状中的代码?

im9ewurl  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(82)

是否可以使用Excel将一列Excel单元格复制到单独的PowerPoint形状中?(例如,单元格A1 =它自己的PowerPoint形状)。
任何关于从哪里开始的提示都将非常有帮助!
我尝试了另一个帖子的旧脚本,但没有放上单独的形状。

yyhrrdl8

yyhrrdl81#

试试看吧

Option Explicit
Sub CreatePresentation()
    Dim pptApp, pptPresentation
    Dim pptSlide, pptShape
    Dim c As Range, i As Integer
    const EXCEL_DATA_RANGE = "A1:A3" ' Update as needed
    Const msoTextOrientationHorizontal = 1
    Const ppLayoutText = 2
    Set pptApp = GetObject(, "PowerPoint.Application")
    If pptApp Is Nothing Then
        Set pptApp = CreateObject("PowerPoint.Application")
        If pptApp Is Nothing Then Exit Sub
    End If
    pptApp.Visible = True
    ' Add a presentation
    Set pptPresentation = pptApp.Presentations.Add
    ' Add a slide
    Set pptSlide = pptPresentation.Slides.Add(1, ppLayoutText)
    i = 1
    For Each c In Range(EXCEL_DATA_RANGE)
        ' Add a shape, update location and size as needed
        Set pptShape = pptSlide.Shapes.AddShape(Type:=msoTextOrientationHorizontal, _
            Left:=100, Top:=50 + 60 * i, Width:=100, Height:=50)
        ' Update text on shape
        pptShape.TextFrame.TextRange.Text = c.Value
        i = i + 1
    Next c
    ' Savt ppt file
    ' pptPresentation.SaveAs "D:\Excel2PPT.pptx"
End Sub

相关问题