如何将多个 Excel 图表粘贴到 PowerPoint 演示文稿中?
How to paste multiple Excel charts into a PowerPoint presentation?
我正在尝试将 Excel 中的图表粘贴到特定位置的 PowerPoint 中。
粘贴第二张幻灯片时出现错误
Invalid request. To select a shape its view must be active
我见过使用 ActiveWindow.View.GotoSlide oSlide.SlideIndex
并且我知道我要做什么。我只是不知道如何实现这个。
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
如果您只是 select 幻灯片:
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
将图表复制到 PowerPoint 幻灯片后,您可能希望通过更改图片属性来移动和缩放它们。
我正在尝试将 Excel 中的图表粘贴到特定位置的 PowerPoint 中。
粘贴第二张幻灯片时出现错误
Invalid request. To select a shape its view must be active
我见过使用 ActiveWindow.View.GotoSlide oSlide.SlideIndex
并且我知道我要做什么。我只是不知道如何实现这个。
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
如果您只是 select 幻灯片:
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
将图表复制到 PowerPoint 幻灯片后,您可能希望通过更改图片属性来移动和缩放它们。