1

If i have texts(shapes) in my powerpoint. How can i modify my code NOT to create a new shape but overwrite the value inside it.

The code below creates a new shape. Any Ideas?

Private Sub test()
Dim xlApp As Object
Dim xlWorkBook As Object

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = False
Set xlWorkBook = xlApp.Workbooks.Open("D:\ELE_powerpoint\book1.xlsx", True, False)

With xlWorkBook.ActiveSheet
xlWorkBook.sheets(1).Range("A2").Copy
End With

ActivePresentation.Slides(1).Shapes.Paste.Select

Set xlApp = Nothing
Set xlWorkBook = Nothing


End Sub
ante011
  • 99
  • 12

2 Answers2

1

lets use a variable instead of copying and pasting like this

mytext = xlWorkBook.sheets(1).Range("A2")

you can then set the text value of a shape like this

ActivePresentation.Slides(1).Shapes("Shape name").TextFrame.Characters.Text = myText

read about how to set the name of a shape here: How to name an object within a PowerPoint slide?

Community
  • 1
  • 1
ebrts
  • 361
  • 2
  • 7
  • 17
1

You need to find the index of the shape you want to paste into. Say it is index 2

Then use

ActivePresentation.Slides(1).Shapes(2).TextFrame.TextRange.Paste
John Coleman
  • 51,337
  • 7
  • 54
  • 119