Sub LineUpMyCharts(Pres As PowerPoint.Presentation)
Dim MyWidth As Single, MyHeight As Single
Dim NumWide As Long
Dim iChtIy As Long, iChtCt As Long, iChtSl As Long
Dim strName As String
Dim sngLeft As Single
Dim sngTop As Single
Dim lngChartPerRow As Long
Dim lngChartPerGroup As Long
Dim shpChtPic As ShapeRange
MyWidth = 650
MyHeight = 180
NumWide = 3
sngLeft = 1
sngTop = MyHeight
strName = ""
lngChartPerRow = 1
lngChartPerGroup = 3
iChtCt = ActiveSheet.ChartObjects.Count
For iChtIy = 1 To iChtCt
With ActiveSheet.ChartObjects(iChtIy)
.Width = MyWidth
.Height = MyHeight
.Left = sngLeft
.Top = sngTop
strName = strName & .Name & ","
End With
If iChtIy Mod lngChartPerRow = 0 Then
sngTop = sngTop + MyHeight
sngLeft = 1
Else
sngLeft = sngLeft + MyWidth
End If
If iChtIy Mod lngChartPerGroup = 0 Then
strName = Left(strName, Len(strName) - 1)
Set shpChtPic = ActiveSheet.Shapes.Range(Split(strName, ","))
shpChtPic.Group
ChartToPPT Pres, shpChtPic
shpChtPic.Ungroup
strName = ""
End If
Next
End Sub
Sub ChartToPPT(Pres As PowerPoint.Presentation, ChartPic As ShapeRange)
' to test this code, paste it into an Excel module
' add a reference to the PowerPoint-library this is done from the Tools ---> References menu path and you
'need to find the microsoft powerpoint check box and check it. Then excel can use ppt objects within itself
Dim pptSlide As PowerPoint.slide
Dim pptShape As PowerPoint.Shape
With Pres.Slides
Set pptSlide = .Add(.Count + 1, ppLayoutTitleOnly)
ChartPic.Parent.Shapes(ChartPic.Name).CopyPicture
With pptSlide
.Shapes(1).TextFrame.TextRange.Text = "Slide Title"
.Shapes.PasteSpecial ppPasteDefault
With .Shapes(.Shapes.Count)
.Left = 120
.Top = 125.125
.Width = 480
.Height = 289.625
End With
End With
End With
End Sub
Sub Main()
Dim pptApp As PowerPoint.Application
Dim pptPres As PowerPoint.Presentation
Set pptApp = CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres = pptApp.Presentations.Add(msoTrue)
LineUpMyCharts pptPres
Set pptPres = Nothing
End Sub
Bookmarks