grubarbarian
New Member
- Joined
- Jun 29, 2016
- Messages
- 12
Dear Wizards,
I have the following script that works great for going through a multi-worksheet excel file and copying and pasting the plots onto a new slide in PowerPoint. My problem is that some worksheets have 2 or more charts on them and I would like to develop the code below so that when there are more than one chart per worksheet that these charts to be displayed on one single PowerPoint slide (ie) 2 or more charts per single slide, whilst maintaining the feature that the other worksheets that have only 1 chart are still plotted on a singe slide.
Many thanks in advance,
Sub ExportChartsToPowerPoint_SingleWorkbook()
'declare PowerPoint Variables
Dim PPTApp As PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim SldIndex As Integer
'declare an Excel Object Variables
Dim Chrt As ChartObject
Dim WrkSht As Worksheet
'Create a new instance of PowerPoint
Set PPTApp = New PowerPoint.Application
PPTApp.Visible = True
'Create a new Presentation within the application
Set PPTPres = PPTApp.Presentations.Add
'CREATE AN INDEX HANDLER FOR SLIDE CREATION
SldIndex = 1
'Loop through all of the worksheet in the ACTIVE workbook
For Each WrkSht In Worksheets
'Loop through all the chart objects on the ACTIVE sheet
For Each Chrt In WrkSht.ChartObjects
'Copy the chart
Chrt.Copy
'Create a new slide, set the layout to blank, and paste the chart on the slide
Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
PPTSlide.Shapes.Paste
'Increment our slide index
SldIndex = SldIndex + 1
Next Chrt
Next WrkSht
End Sub
I have the following script that works great for going through a multi-worksheet excel file and copying and pasting the plots onto a new slide in PowerPoint. My problem is that some worksheets have 2 or more charts on them and I would like to develop the code below so that when there are more than one chart per worksheet that these charts to be displayed on one single PowerPoint slide (ie) 2 or more charts per single slide, whilst maintaining the feature that the other worksheets that have only 1 chart are still plotted on a singe slide.
Many thanks in advance,
Sub ExportChartsToPowerPoint_SingleWorkbook()
'declare PowerPoint Variables
Dim PPTApp As PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim SldIndex As Integer
'declare an Excel Object Variables
Dim Chrt As ChartObject
Dim WrkSht As Worksheet
'Create a new instance of PowerPoint
Set PPTApp = New PowerPoint.Application
PPTApp.Visible = True
'Create a new Presentation within the application
Set PPTPres = PPTApp.Presentations.Add
'CREATE AN INDEX HANDLER FOR SLIDE CREATION
SldIndex = 1
'Loop through all of the worksheet in the ACTIVE workbook
For Each WrkSht In Worksheets
'Loop through all the chart objects on the ACTIVE sheet
For Each Chrt In WrkSht.ChartObjects
'Copy the chart
Chrt.Copy
'Create a new slide, set the layout to blank, and paste the chart on the slide
Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
PPTSlide.Shapes.Paste
'Increment our slide index
SldIndex = SldIndex + 1
Next Chrt
Next WrkSht
End Sub