notlad1974
New Member
- Joined
- Dec 17, 2010
- Messages
- 6
I am quite new to Visual Basic. I have created the below code to pull 3 slides from an Excel workbook into a preformatted Powerpoint deck. I would prefer to have it paste keeping the source (Excel) formatting and Data Link. I cannot figure out how to do so. Any help would be greatly appreciated. Thanks!
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
' 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 # 2
' Copy "Chart 1" on "Sheet1" as a picture
ActiveWorkbook.Sheets("Global Bookings Summary").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(1).Shapes.PasteSpecial
' Align pasted chart
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
'Copy "Chart 1" to from "Sheet3" to Slide # 4
' Copy "Chart 1" on "Sheet3" as a picture
ActiveWorkbook.Sheets("Global IQRR by Seg").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(2).Shapes.PasteSpecial
With ActiveChart.Parent
.Height = 638 ' resize
.Width = 1000 ' resize
.Top = 1 ' reposition
.Left = 1 ' reposition
End With
'Copy "Chart 1" to from "Sheet3" to Slide # 4
' Copy "Chart 1" on "Sheet3" as a picture
ActiveWorkbook.Sheets("Global Loss Analysis Chart").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(3).Shapes.PasteSpecial
' Align pasted chart
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End With
End Sub
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
' 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 # 2
' Copy "Chart 1" on "Sheet1" as a picture
ActiveWorkbook.Sheets("Global Bookings Summary").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(1).Shapes.PasteSpecial
' Align pasted chart
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
'Copy "Chart 1" to from "Sheet3" to Slide # 4
' Copy "Chart 1" on "Sheet3" as a picture
ActiveWorkbook.Sheets("Global IQRR by Seg").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(2).Shapes.PasteSpecial
With ActiveChart.Parent
.Height = 638 ' resize
.Width = 1000 ' resize
.Top = 1 ' reposition
.Left = 1 ' reposition
End With
'Copy "Chart 1" to from "Sheet3" to Slide # 4
' Copy "Chart 1" on "Sheet3" as a picture
ActiveWorkbook.Sheets("Global Loss Analysis Chart").ChartObjects("Chart 1").Chart.ChartArea.Copy
' Paste chart to Slide # 4
With PPPres.Slides(3).Shapes.PasteSpecial
' Align pasted chart
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End With
End Sub