I'm trying to paste charts from Excel being into PowerPoint in specific locations.
I get an error when pasting a second slide
Invalid request. To select a shape its view must be active
I have seen to use ActiveWindow.View.GotoSlide oSlide.SlideIndex
and I know what I'm trying to do. I just do not know how to implement this.
Sub ChartToPresentation()
' Uses Early Binding to the PowerPoint Object Model
' 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 nPlcHolder As Long
' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
'Copy "Chart 1" on "Sheet1" to Slide # 1
' Copy "Chart 1" on "Sheet1" as a picture and want to paste to placeholder
ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").CopyPicture
' Paste chart to Slide # 1
With PPPres
nPlcHolder = 2 '<~~ The place holder where you have to paste
.Slides(1).Shapes.Placeholders(nPlcHolder).Select msoTrue
.Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With
'Copy "Chart 5" on "Sheet1" to Slide # 2
ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 5").CopyPicture
' Paste chart to Slide # 2
With PPPres
nPlcHolder = 2 '<~~ The place holder where you have to paste
.Slides(2).Shapes.Placeholders(nPlcHolder).Select msoTrue
.Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With
End Sub
If you just select the slides it works:
With PPPres
nPlcHolder = 2 '<~~ The place holder where you have to paste
'.Slides(1).Shapes.Placeholders(nPlcHolder).Select msoTrue
.Slides(1).Select
.Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With
[...]
With PPPres
nPlcHolder = 2 '<~~ The place holder where you have to paste
'.Slides(2).Shapes.Placeholders(nPlcHolder).Select msoTrue
.Slides(2).Select
.Windows(1).View.PasteSpecial (ppPasteMetafilePicture)
End With
After copying the charts to your PowerPoint slides you may want to move and zoom them by changing their picture properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.