If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Charts in each sheet to Powerpoint
Hi everybody,
I have created an Excel file with multiple charts, each of them is on a single sheet. I'm trying to create a macro to copy each slide, paste it on a powerpoint slide, get to the next sheet, to copy the slide, paste it on the next powerpoint slide, and so on till the end. Here's the code. I'm stuck when I try to copy the chart. Does anyone know a simple way to achieve that ? Thanks Sub GraphPowerpoint() Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PresentationFileName As Variant Dim SlideCount As Long Dim iCht As Integer Set PPApp = CreateObject("Powerpoint.Application") PPApp.Visible = True Set PPPres = PPApp.Presentations.Add(msoTrue) Set PPSlide = PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType = ppViewSlide For Each f In Worksheets Sheets(f.Name).Activate ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture SlideCount = PPPres.Slides.Count Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank) With PPSlide .Shapes.Paste End With PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True SlideCount = SlideCount + 1 Next End Sub |
#2
|
|||
|
|||
If the charts are each on their own chart sheet, not embedded on their
own worksheet, the following modifications should help. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ Sub GraphPowerpoint() Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PresentationFileName As Variant Dim SlideCount As Long Dim iCht As Integer Dim f As Object Set PPApp = CreateObject("Powerpoint.Application") PPApp.Visible = True Set PPPres = PPApp.Presentations.Add(msoTrue) Set PPSlide = PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType = ppViewSlide For Each f In ActiveWorkbook.Charts f.Activate ActiveChart.CopyPicture Appearance:=xlScreen, _ Size:=xlScreen, Format:=xlPicture SlideCount = PPPres.Slides.Count Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank) With PPSlide .Shapes.Paste End With PPApp.ActiveWindow.Selection.ShapeRange.Align _ msoAlignCenters, True PPApp.ActiveWindow.Selection.ShapeRange.Align _ msoAlignMiddles, True SlideCount = SlideCount + 1 Next End Sub wrote: Hi everybody, I have created an Excel file with multiple charts, each of them is on a single sheet. I'm trying to create a macro to copy each slide, paste it on a powerpoint slide, get to the next sheet, to copy the slide, paste it on the next powerpoint slide, and so on till the end. Here's the code. I'm stuck when I try to copy the chart. Does anyone know a simple way to achieve that ? Thanks Sub GraphPowerpoint() |
#3
|
|||
|
|||
Thanks Jon. It works fine;;;except I have trouble with
PPApp.ActiveWindow.Selection.S=ADhapeRange.Align msoAlignCenters, True PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True It doesn't want to align the chart. I'm sure you know what I should do. Thank you again. |
#4
|
|||
|
|||
Is the chart selected?
This PPApp.ActiveWindow.Selection.S*hapeRange.Align msoAlignCenters, True can be replaced with this PPApp.ActiveWindow.Selection.sliderange.Shapes.ran ge _ (ppapp.ActiveWindow.Selection.sliderange.Shapes.Co unt).align _ msoAlignCenters, True Certainly it isn't shorter, but it might help. The PowerPoint object model is not quite as intuitive as Excel's: no ActiveSlide object, for example. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ wrote: Thanks Jon. It works fine;;;except I have trouble with PPApp.ActiveWindow.Selection.S*hapeRange.Align msoAlignCenters, True PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True It doesn't want to align the chart. I'm sure you know what I should do. Thank you again. |
#5
|
|||
|
|||
Thanks Jon.
There must be something I don't get because it's not working fine. Here's my code : Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PresentationFileName As Variant Dim SlideCount As Long Dim iCht As Integer Dim f As Object Set PPApp =3D CreateObject("Powerpoint.Application") PPApp.Visible =3D True ' Ins=E8re une nouvelle presentation. Set PPPres =3D PPApp.Presentations.Add(msoTrue) Set PPSlide =3D PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType =3D ppViewSlide ' Copie le graphique en image For Each f In ActiveWorkbook.Charts Sheets(f.Name).Activate ActiveChart.CopyPicture Appearance:=3DxlScreen, Size:=3DxlScreen, Format:=3DxlPicture SlideCount =3D PPPres.Slides.Count Set PPSlide =3D PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank) With PPSlide .Shapes.Paste End With PPApp.ActiveWindow.Selection.SlideRange.Shapes.Ran ge(PPApp.ActiveWindow.Sel= ection.SlideRange.Shapes.Count).Align msoAlignCenters, True SlideCount =3D SlideCount + 1 =20 Next Can you tell me what's wrong ? Except ME !! Thank you. |
#6
|
|||
|
|||
I have noticed an error in what I posted earlier (sorry!), but the
following procedure works just fine: Sub ChartSheetsToPowerPointSlides() Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PresentationFileName As Variant Dim SlideCount As Long Dim iCht As Integer Dim f As Object Set PPApp = CreateObject("Powerpoint.Application") PPApp.Visible = True ' Insère une nouvelle presentation. Set PPPres = PPApp.Presentations.Add(msoTrue) Set PPSlide = PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType = ppViewSlide ' Copie le graphique en image For Each f In ActiveWorkbook.Charts ' don't need to activate the slide f.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _ Format:=xlPicture SlideCount = PPPres.Slides.Count ' insert new slide for each chart picture Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank) With PPSlide .Shapes.Paste .Shapes.Range(.Shapes.Count).Align msoAlignCenters, True .Shapes.Range(.Shapes.Count).Align msoAlignMiddles, True End With Next End Sub - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ wrote: Thanks Jon. There must be something I don't get because it's not working fine. Here's my code : Dim PPApp As PowerPoint.Application Dim PPPres As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PresentationFileName As Variant Dim SlideCount As Long Dim iCht As Integer Dim f As Object Set PPApp = CreateObject("Powerpoint.Application") PPApp.Visible = True ' Insère une nouvelle presentation. Set PPPres = PPApp.Presentations.Add(msoTrue) Set PPSlide = PPPres.Slides.Add(1, ppLayoutBlank) PPApp.ActiveWindow.ViewType = ppViewSlide ' Copie le graphique en image For Each f In ActiveWorkbook.Charts Sheets(f.Name).Activate ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture SlideCount = PPPres.Slides.Count Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutBlank) With PPSlide .Shapes.Paste End With PPApp.ActiveWindow.Selection.SlideRange.Shapes.Ran ge(PPApp.ActiveWindow.Selection.SlideRange.Shapes. Count).Align msoAlignCenters, True SlideCount = SlideCount + 1 Next Can you tell me what's wrong ? Except ME !! Thank you. |
#7
|
|||
|
|||
Many Thanks, Jon !! It works just fine and saves me time !
Thanks again for your precious help ! |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Why are my Powerpoint charts getting stretched on my widescreen? | Adam Snow | Powerpoint | 13 | July 8th, 2005 04:39 PM |
edit excel charts in powerpoint 2003 | Alan Ball | General Discussions | 10 | June 2nd, 2005 12:28 AM |
Editing Org 2.0 charts with PowerPoint 2003 | Rob Nicholson | Powerpoint | 5 | May 25th, 2005 09:47 PM |
How Can I keep a PowerPoint table in sync with an Excel sheet? | Bill Cloneton | Powerpoint | 2 | May 16th, 2005 05:52 AM |
Pie charts in Excel and Powerpoint | Colleen | Charts and Charting | 1 | August 25th, 2004 08:22 PM |