Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Export chart to PowerPoint

I found some code here to export a chart from Excel to PowerPoint. What I
want it to do is to export the chart to a new slide at the end of the
presentation. now have to following code :

Public Sub ChartToPowerPoint()

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim NewIndex As Integer

Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewNormal

NewIndex = PPPres.Slides.Count + 1
PPPres.Slides.Add(Index:=NewIndex, Layout:=ppLayoutBlank).Select

PPPres.Slides(NewIndex).Select
Set PPSlide = PPPres.Slides
_(PPApp.ActiveWindow.Selection.SlideRange.SlideInd ex)

ActiveSheet.ChartObjects("Graph01").Activate
ActiveChart.ChartArea.Select

ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen,
Format:=xlBitmap

PPSlide.Shapes.Paste.Select

PPApp.ActiveWindow.Selection.ShapeRange.Height = 303.5
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

End Sub


If there is no slide in the presentation, it works 1 time, 2 times, n times.

If there is 1 slide in the presentation it fails the first time (end macro)
and it works the second time and third time and n time.

If at some time I go to the PP presentation and select another slide
manually, and start the macro after that, it fails the first time, (end
macro) and it works the second time and third time and n time.

The error message that I get for "PPSlide.Shapes.Paste.Select" is :

Run-time error '-2147188160(80048240)':
Shape (unknown member) : Invalid request. To select a shape its view must be
active.

I can not find out why the shape (which is copied to the last slide of the
presentation, by the way) is not active at that moment. Neither can I find a
way to activate it.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Export chart to PowerPoint

Try these changes. I think part of your problem is where the SELECTION is
putting the focus. The macro may be getting confused betweeen the excel
application and the power point application. I eliminated the select. I
also used CreateObject rather than getObject.


Public Sub ChartToPowerPoint()

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim NewIndex As Integer

Set PPApp = CreateObject("Powerpoint.Application")
PPApp.Visible = True
Set PPPres = PPApp.Presentations.Add

NewIndex = PPPres.Slides.Count + 1
Set PPSlide = PPPres.Slides.Add(Index:=NewIndex, Layout:=ppLayoutBlank)

ActiveSheet.ChartObjects("Graph01").Activate
Set Chrt = ActiveChart.ChartArea

Chrt.CopyPicture _
Appearance:=xlScreen, _
Size:=xlScreen, _
Format:=xlBitmap

PPSlide.Shapes.Paste

PPApp.ActiveWindow.Selection.ShapeRange.Height = 303.5
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

End Sub


"Henk" wrote:

I found some code here to export a chart from Excel to PowerPoint. What I
want it to do is to export the chart to a new slide at the end of the
presentation. now have to following code :

Public Sub ChartToPowerPoint()

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim NewIndex As Integer

Set PPApp = GetObject(, "Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewNormal

NewIndex = PPPres.Slides.Count + 1
PPPres.Slides.Add(Index:=NewIndex, Layout:=ppLayoutBlank).Select

PPPres.Slides(NewIndex).Select
Set PPSlide = PPPres.Slides
_(PPApp.ActiveWindow.Selection.SlideRange.SlideInd ex)

ActiveSheet.ChartObjects("Graph01").Activate
ActiveChart.ChartArea.Select

ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen,
Format:=xlBitmap

PPSlide.Shapes.Paste.Select

PPApp.ActiveWindow.Selection.ShapeRange.Height = 303.5
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True

Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

Exit Sub

End Sub


If there is no slide in the presentation, it works 1 time, 2 times, n times.

If there is 1 slide in the presentation it fails the first time (end macro)
and it works the second time and third time and n time.

If at some time I go to the PP presentation and select another slide
manually, and start the macro after that, it fails the first time, (end
macro) and it works the second time and third time and n time.

The error message that I get for "PPSlide.Shapes.Paste.Select" is :

Run-time error '-2147188160(80048240)':
Shape (unknown member) : Invalid request. To select a shape its view must be
active.

I can not find out why the shape (which is copied to the last slide of the
presentation, by the way) is not active at that moment. Neither can I find a
way to activate it.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PowerPoint export to Excel ergoguy Excel Programming 0 January 1st 08 12:52 AM
how do i create a macro to export a chart to powerpoint? NPAT Charts and Charting in Excel 1 November 16th 07 10:23 AM
Help with VBA export of cells to PowerPoint JOTS Excel Programming 0 June 15th 06 06:11 PM
Export from Excel to Powerpoint Martin Los[_3_] Excel Programming 2 December 22nd 04 09:37 AM
How to export a picture or chart from Excel to PowerPoint? RADO[_3_] Excel Programming 2 November 3rd 03 01:15 PM


All times are GMT +1. The time now is 03:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"