Excel チャートを PowerPoint に非表示オブジェクトとして貼り付けたいが、埋め込み OLEObject として維持したい場合は、OLEObject として貼り付けることをお勧めします。貼り付けは次のようになります。
'Create a new slide in the Presentation, set the layout to blank, and paste chart on to the newly added slide.
Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
PPTSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
ワークブック全体で複数のグラフを、リンクなしで OLEObject として PowerPoint プレゼンテーションに貼り付ける簡単なコードを次に示します。
Sub ExportChartsToPowerPoint_MultipleWorksheets()
' OVERVIEW:
' This script will loop through all the worksheets in the Active Workbook
' and copy all the Charts to a new PowerPoint presentation that we create.
' Each chart will get their own individual slide and will be placed in the center of it.
'Declare PowerPoint Variables
Dim PPTApp As PowerPoint.Application
Dim PPTPres As PowerPoint.Presentation
Dim PPTSlide As PowerPoint.Slide
Dim PPTShape As PowerPoint.Shape
Dim SldIndex As Integer
'Declare Excel Variables
Dim Chrt As ChartObject
Dim WrkSht As Worksheet
'Create new PowerPoint Application & make it visible.
Set PPTApp = New PowerPoint.Application
PPTApp.Visible = True
'Create new presentation in the PowerPoint application.
Set PPTPres = PPTApp.Presentations.Add
'Create an index handler for slide creation.
SldIndex = 1
'Loop throught all the Worksheets in the Worksheets Collection.
For Each WrkSht In Worksheets
'Loop through all the CHARTOBJECTS in the ACTIVESHEET.
For Each Chrt In WrkSht.ChartObjects
'Copy the Chart
Chrt.Chart.ChartArea.Copy
'Create a new slide in the Presentation, set the layout to blank, and paste chart on to the newly added slide.
Set PPTSlide = PPTPres.Slides.Add(SldIndex, ppLayoutBlank)
PPTSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoFalse
'Increment index so that way we paste the next chart on the new slide that is added.
SldIndex = SldIndex + 1
Next Chrt
Next WrkSht
End Sub
さて、これは実際に私の YouTube ビデオの 1 つにあるコードです。このコード全体を確認したい場合は、以下のリンクにアクセスすることをお勧めします。
https://youtu.be/DOaBtYMCCEM
完全な開示 これは私の個人的な YouTube チャンネルです。