I have to copy text from a cell in Excel to a textbox in PPT using excel-vba. I have the following code:
ActivePresentation.Shapes(tb).TextFrame.Characters.Text = ActiveSheet.Range("C41").Value
But this code is giving the error "method or data member bot found" for Shapes. What is the correct way to do it?
Thanks in advance
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.