work4livinsean
Programmer
Hi everyone, I need to export a chart from Excel into PowerPoint on multiple slides. I got this code to work! The problem is that I want it to place the charts on lets say slides 1, 3, and 5. Right now the code places the chart in sequencial order. I was thinking for the if statement to place a statement like the:
'If slideindex = 1 or slideindex = 3 or slideindex = 5 Then'
Please help!
Sub TestNew()
Dim objPPT As Object
Dim objPrs As Object
Dim shtTemp As Worksheet
Dim chtTemp As ChartObject
Dim intSlide As Integer
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
objPPT.presentations.Open ThisWorkbook.Path & "\TestPP.ppt"
For Each shtTemp In ThisWorkbook.Worksheets
For Each chtTemp In shtTemp.ChartObjects
intSlide = intSlide + 1
chtTemp.CopyPicture
If intSlide > objPPT.presentations(1).Slides.Count Then 'I think this if statement needs to be changed
objPPT.ActiveWindow.View.GotoSlide Index:=objPPT.presentations(1).Slides.Add(Index:=intSlide, Layout:=1).slideindex
Else
objPPT.ActiveWindow.View.GotoSlide intSlide
End If
objPPT.ActiveWindow.View.Paste 'This may have to be moved if the if statement is changed
Next
Next
Set objPrs = Nothing
Set objPPT = Nothing
End Sub
Thanks in advanced!
'If slideindex = 1 or slideindex = 3 or slideindex = 5 Then'
Please help!
Sub TestNew()
Dim objPPT As Object
Dim objPrs As Object
Dim shtTemp As Worksheet
Dim chtTemp As ChartObject
Dim intSlide As Integer
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
objPPT.presentations.Open ThisWorkbook.Path & "\TestPP.ppt"
For Each shtTemp In ThisWorkbook.Worksheets
For Each chtTemp In shtTemp.ChartObjects
intSlide = intSlide + 1
chtTemp.CopyPicture
If intSlide > objPPT.presentations(1).Slides.Count Then 'I think this if statement needs to be changed
objPPT.ActiveWindow.View.GotoSlide Index:=objPPT.presentations(1).Slides.Add(Index:=intSlide, Layout:=1).slideindex
Else
objPPT.ActiveWindow.View.GotoSlide intSlide
End If
objPPT.ActiveWindow.View.Paste 'This may have to be moved if the if statement is changed
Next
Next
Set objPrs = Nothing
Set objPPT = Nothing
End Sub
Thanks in advanced!