'Change Slide Title while copying chart from excel to powerpoint
I have written a code to copy charts dynamically from an excel workbook to a PowerPoint presentation. What I am trying to do now is change the slide titles for each slide dynamically.
here is a snippet of the code :
PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1, ppLayoutBlank
PPApp.ActiveWindow.View.GotoSlide PPApp.ActivePresentation.Slides.Count
Sheets("sheet1").Range("V1").Value = h
Sheets("sheet1").Range("V11").Value = j
Sheets("sheet1").Range("V22").Value = k
Sheets("sheet1").Select
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveSheet.ChartObjects("Chart 5").CopyPicture
PPApp.ActiveWindow.View.Paste
eachslideheader = Range("v2").Text & "my chart"
PPApp.ActivePresentation.Slides.ppLayoutTitle.Add
PPApp.ActivePresentation.Slides.pplayouTitle.TextFrame.TextRange.Text = eachslideheader
This code gives an error while insert the title I am unable to figure it out.
Solution 1:[1]
' Assuming you're running this from w/in Excel ...
Dim oSl as Object
' Get a reference to the added slide object to make things simpler later
' Make the new slide a TitleOnly layout so that it automatically gets a title
' placeholder:
Set oSl = PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1, _
ppLayoutTitleOnly
' ppLayoutTitleOnly = 11
PPApp.ActiveWindow.View.GotoSlide PPApp.ActivePresentation.Slides.Count
Sheets("sheet1").Range("V1").Value = h
Sheets("sheet1").Range("V11").Value = j
Sheets("sheet1").Range("V22").Value = k
Sheets("sheet1").Select
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveSheet.ChartObjects("Chart 5").CopyPicture
PPApp.ActiveWindow.View.Paste
eachslideheader = Range("v2").Text & "my chart"
' PPApp.ActivePresentation.Slides.ppLayoutTitle.Add
' PPApp.ActivePresentation.Slides.pplayouTitle.TextFrame.TextRange.Text = eachslideheader
oSl.Shapes.Title.Textframe.TextRange.Text = eachslideheader
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ripster |