copy text from Excel cell to PPT textbox

僤鯓⒐⒋嵵緔 提交于 2019-12-06 02:17:46

You are getting an error becuase you have not specified where the shape is. I mean which slide???

See this example. (tried and tested from Excel)

Amend as applicable.

Code:

Option Explicit

Sub Sammple()
    Dim oPPApp As Object, oPPPrsn As Object, oPPSlide As Object
    Dim oPPShape As Object
    Dim FlName As String

    '~~> Change this to the relevant file
    FlName = "C:\MyFile.PPTX"

    '~~> Establish an PowerPoint application object
    On Error Resume Next
    Set oPPApp = GetObject(, "PowerPoint.Application")

    If Err.Number <> 0 Then
        Set oPPApp = CreateObject("PowerPoint.Application")
    End If
    Err.Clear
    On Error GoTo 0

    oPPApp.Visible = True

    '~~> Open the relevant powerpoint file
    Set oPPPrsn = oPPApp.Presentations.Open(FlName)
    '~~> Change this to the relevant slide which has the shape
    Set oPPSlide = oPPPrsn.Slides(1)
    '~~> Change this to the relevant shape
    Set oPPShape = oPPSlide.Shapes(1)

    '~~> Write to the shape
    oPPShape.TextFrame.TextRange.Text = _
    ThisWorkbook.Sheets("Sheet1").Range("C41").Value

    '
    '~~> Rest of the code
    '
End Sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!