View Full Version : VBA to paste excel charts to ppt in editable format.
kevvukeka
04-29-2013, 08:26 AM
HI Everyone,
I have the below code which pastes, excel chart to ppt slides as a picture. I want to paste these charts in editable format. Can anyone help me with the editing of this code.
I use office 2007 at my work.
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("Sheet1").ChartObjects("Chart
1").CopyPicture
' Paste
chart to Slide # 2
With
PPPres.Slides(2).Shapes.Paste
' Align pasted
chart
.Align msoAlignCenters,
True
.Align msoAlignMiddles, True
End
With
' Clean up
Set PPSlide =
Nothing
Set PPPres =
Nothing
Set PPApp =
Nothing
End Sub
Thanks a lot for your help!!!!
Regards,
Praveen
John Wilson
04-29-2013, 08:39 AM
You are copying the chart as a picture!
' Copy "Chart 1" on "Sheet1" As a picture
ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").CopyPicture
So you will get a picture when you paste!
Just change the line to:
ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").Copy
kevvukeka
04-29-2013, 09:01 AM
Hi John,
Thanks for the reply. I just realized those are not sheets but charts.so referrring the sheet number is giving an error.
Its chart10(BRT - Aided AD) in which there is a singlhe chart which i need to copy.
I tried this but get an error.
ActiveWorkbook.Charts(10).ChartObjects("Chart 1").Copy
With PPPres.Slides(10).Shapes.Paste
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
kevvukeka
04-29-2013, 09:45 AM
Hi John,
Kindly help. I want to paste the chart from "BRT - Aided AD AW" to slide 10 and align it to center and middle. I am not able to fix the below code to do so.
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
ActiveWorkbook.Charts("BRT - AIDED AD AW ").Copy
' Paste chart to Slide # 10
PPPres.Slides(10).Shapes.Paste
With ActiveWindow.shapes(1)
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
can you help?
Regards,
Praveen
John Wilson
04-29-2013, 11:37 PM
I'm not really an Excel coder but this might do it:
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
ActiveWorkbook.Sheets("BRT - AIDED AD AW").Activate
ActiveChart.ChartArea.Copy
' Paste chart to Slide # 10
With PPPres.Slides(10).Shapes.Paste
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
End With
' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing
End Sub
kevvukeka
04-30-2013, 03:51 AM
Hi John,
Thanks for the help. I made a little change and its working. Thanks again.
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
ActiveWorkbook.Charts("BRT -
AIDED AD AW ").Select
ActiveChart.ChartArea.Copy
' Paste chart
to Slide # 10
With PPPres.Slides(10).Shapes.Paste
.Align
msoAlignCenters, True
.Align msoAlignMiddles, True
End
With
' Clean up
Set PPSlide = Nothing
Set PPPres =
Nothing
Set PPApp = Nothing
End Sub
John Wilson
04-30-2013, 04:16 AM
Glad it works. There should be no need to select the chart though. Activating a chart sheet should automatically make the chart the active chart.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.