ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Powerpoint charting from excel (https://www.excelbanter.com/excel-programming/298322-powerpoint-charting-excel.html)

KJD

Powerpoint charting from excel
 
Hi,

I have put my code below that I am attempting to open
PowerPoint and insert a new slide containing a chart -
however when I try to access the chart (lines highlighted
with a *** below) the program crashes - is there anyone
who can help me with the correct code please?

Many thanks in advance

KJD


Dim oPPTShape As PowerPoint.Shape
Dim rngNewRange As Excel.Range
Dim oGraph As Object
Dim lLastSlide As Long

' Change this to the auto layout you want to use. This
value can be
' any PpSlideLayout constant.
Const DEFAULT_AUTO_LAYOUT As Long = ppLayoutChart
' Get the number of slides in the active presentation.
lLastSlide = oPPTApp.ActivePresentation.Slides.Count
lLastSlide = lLastSlide + 1
oPPTApp.ActivePresentation.Slides.Add lLastSlide,
DEFAULT_AUTO_LAYOUT

With oPPTApp.ActivePresentation.Slides(lLastSlide)
With .Shapes(1)
With .TextFrame.TextRange
.Text = chart_title
.Font.Name = "Arial"
.Font.Size = 24
End With
End With
Set oPPTShape = oPPTApp.ActivePresentation.Slides
(lLastSlide).Shapes(2)
**** oPPTShape.OLEFormat.Activate
**** Set rngNewRange = Sheets("charts").Range
(chart_range)
**** Sheets("charts").Select
**** Range(chart_range).Select
**** rngNewRange.Copy
**** Set oGraph = .OLEFormat.Object
**** oGraph.Application.DataSheet.Range
("A0:Z100").Delete
**** oGraph.Application.DataSheet.Range
("A0").Paste False
**** oGraph.Application.Update
Set oPPTShape = Nothing
End With



Jon Peltier[_7_]

Powerpoint charting from excel
 
You have Excel, why not create a real chart in Excel, and paste it into
PowerPoint?

http://peltiertech.com/Excel/XL_PPT.html

If you insist on using it, the PowerPoint FAQ page has some hints for
automating MS Graph:

http://www.rdpslides.com/pptfaq/FAQ00496.htm

Also Shyam Pillai has a bit about VBA and MSG:

http://www.mvps.org/skp/vba.htm

And you could always try the Microsoft Knowledge Base.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______

KJD wrote:

Hi,

I have put my code below that I am attempting to open
PowerPoint and insert a new slide containing a chart -
however when I try to access the chart (lines highlighted
with a *** below) the program crashes - is there anyone
who can help me with the correct code please?

Many thanks in advance

KJD


Dim oPPTShape As PowerPoint.Shape
Dim rngNewRange As Excel.Range
Dim oGraph As Object
Dim lLastSlide As Long

' Change this to the auto layout you want to use. This
value can be
' any PpSlideLayout constant.
Const DEFAULT_AUTO_LAYOUT As Long = ppLayoutChart
' Get the number of slides in the active presentation.
lLastSlide = oPPTApp.ActivePresentation.Slides.Count
lLastSlide = lLastSlide + 1
oPPTApp.ActivePresentation.Slides.Add lLastSlide,
DEFAULT_AUTO_LAYOUT

With oPPTApp.ActivePresentation.Slides(lLastSlide)
With .Shapes(1)
With .TextFrame.TextRange
.Text = chart_title
.Font.Name = "Arial"
.Font.Size = 24
End With
End With
Set oPPTShape = oPPTApp.ActivePresentation.Slides
(lLastSlide).Shapes(2)
**** oPPTShape.OLEFormat.Activate
**** Set rngNewRange = Sheets("charts").Range
(chart_range)
**** Sheets("charts").Select
**** Range(chart_range).Select
**** rngNewRange.Copy
**** Set oGraph = .OLEFormat.Object
**** oGraph.Application.DataSheet.Range
("A0:Z100").Delete
**** oGraph.Application.DataSheet.Range
("A0").Paste False
**** oGraph.Application.Update
Set oPPTShape = Nothing
End With





All times are GMT +1. The time now is 07:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com