I need to insert some diagrams from excel into powerpoint. I found some great VBA code (mostly on the Jon Peltier website). Now my powerpoint template has several layouts (for example, with 1 diagram occupying most of the slides or 1 diagram and one text box on the slide, etc. Etc.).
I want the chart to become part of the slide layout, so if I reformat the slide - for example, I change the layout, as in the above example - the chart will move accordingly. Currently, I can paste in the place where the placeholder is the right size and that's it, but it is not in the placeholder, it is on the placeholder (and therefore it stays there if I change the layout).
Ideally, I would like to be able to select a layout (from 15) and select a placeholder in the selected layout (usually I have a header, footer, and then 1 to 4 placeholders for diagrams, images, text, or all of the above).
I am not a VBA programmer, I just use some logic and capture codes that are kindly transmitted over the network. I don’t know how to determine the correct layout (do they have names, but is this a variable?), Neither a proper placeholder in the layout (here I don’t even know how to identify them).
Any help is greatly appreciated. Df
Below is the code that I copied here and there (mainly the John Peltier site).
Sub ChartToPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim AddSlidesToEnd As Boolean
AddSlidesToEnd = True
' Make sure a chart is selected
If ActiveChart Is Nothing Then
MsgBox "Please select a chart and try again.", vbExclamation, _
"No Chart Selected"
Else
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' Reference active slide
Set PPSlide = PPPres.Slides _
(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
' Copy chart
ActiveChart.ChartArea.Copy
' Paste chart
PPSlide.Shapes.Paste.Select
' Position pasted chart
' This is the keypoint
' I want to replace this with the selection of appropriate layout
' and placeholder in that layout
PPApp.ActiveWindow.Selection.ShapeRange.Left = 19.56
PPApp.ActiveWindow.Selection.ShapeRange.Top = 66.33
PPApp.ActiveWindow.Selection.ShapeRange.Width = 366.8
PPApp.ActiveWindow.Selection.ShapeRange.Height = 424.62
If PPApp.ActivePresentation.Slides.Count = 0 Then
' Other key point
' can I add a specific layout, for example one named Two Content Layout + takeout
Set PPSlide = PPApp.ActivePresentation.Slides.Add(1, ppLayoutBlank)
Else
If AddSlidesToEnd Then
'Appends slides to end of presentation and makes last slide active
PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
PPApp.ActiveWindow.View.GotoSlide PPApp.ActivePresentation.Slides.Count
Set PPSlide = PPApp.ActivePresentation.Slides(PPApp.ActivePresentation.Slides.Count)
Else
'Sets current slide to active slide
Set PPSlide = PPApp.ActiveWindow.View.Slide
End If
End If
'Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End If
End Sub