hi guys. via excel, i open a powerpoint template inside my com (named PptTemplate.pptx) and transfer the values of column A & B to the slides. this is my current code:
Sub ExcelToPpt()
'taken from http://stackoverflow.com/questions/20472964/replace-a-powerpoint-shape-in-excel-vba-without-changing-its-position-number
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 = ThisWorkbook.Path & "\PptTemplate.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)
CountX = 1
With ThisWorkbook.Sheets("Sheet1")
LR = .Cells(Rows.Count, 1).End(xlUp).Row
For RowX = 2 To LR
If .Cells(RowX, "A") <> vbNullString Then
'~~> Change this to the relevant slide which has the shape
Set oPPSlide = oPPPrsn.Slides(CountX)
'~~> Change this to the relevant shape
Set oPPShape = oPPSlide.Shapes(1)
Set oPPShape2 = oPPSlide.Shapes(2)
'~~> Write to the shape
oPPShape.TextFrame.TextRange.Text = .Cells(RowX, "A").Value
oPPShape2.TextFrame.TextRange.Text = .Cells(RowX, "B")
CountX = CountX + 1
End If
Next RowX
End With
End Sub
my question is how do i add slides based on the variable rows in my excel file? the slides must also be of the same design of my current slides. tried the code below but i got an error run-time error 429
Bookmarks