Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel macro to ppt

Status
Not open for further replies.

avnith

ISP
Apr 22, 2010
10
US
I am currently working on a requirement where the excel shoud automate powerpoint..

For eg
Jan Feb Mar
East 10 30 40
West 13 14 45
South 34 35 33

Each row in the excel should generate a seperate slide.
So as per the data we r supposed to have 3 slides..

I was able to code in such a way it works for a single slide and get updated automatically when the months grows
But i am not able to get for more than one slide.Please can you give me a clue to continue..
I am really struck with this

I really thank you for your time.
Keep up with your Good work.
Thanks

My code is pastes below written in MS xl 2003
Sub Chart2PPT()
Dim objPPT As Object
Dim objPrs As Object
Dim objGraph As Object
Dim objDataSheet As Object
Dim rngData As Range
Dim intRow As Integer
Dim intCol As Integer

' excel chart data
Set rngData = Range("A1:J2")
' open powerpoint
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
' existing powerpoint pres
objPPT.Presentations.Open "C:\PPt\Call_volume.ppt"
' chart on slide 2
Set objPrs = objPPT.Presentations(1).slides(2)
' pointer to graph
Set objGraph = objPrs.Shapes(2).OLEFormat.Object.Application
' pointer to graphs data sheet
Set objDataSheet = objGraph.Datasheet
' transfer data
For intRow = 1 To rngData.Rows.Count
For intCol = 1 To rngData.Columns.Count
objDataSheet.Cells(intRow, intCol) = rngData.Cells(intRow, intCol)
Next
Next
' update to keep changes
objGraph.Update
objGraph.Quit
objPPT.Presentations(1).Save


' tidy up objects
Set rngData = Nothing
Set objGraph = Nothing
Set objDataSheet = Nothing
Set objPrs = Nothing
Set objPPT = Nothing
End Sub
 
Hi guys do you know if the code you used works for excel 2007 and Power Point 2007, I have a task very similar to the one described previously, but I am ussing MS office 2007 applications, using your code as a guide I found the following error: RunTime Error 438

This error occurs in the line:
Set objDataSheet = objGraph.DataSheet

I thought the reason was a library object not being enabled, but my code keeps with the error, could you please tell me what the reason may be?

Thanks in advance
 


2007 seems to behave significantly different, I notice.

I cannot find the GRAPH object in ppt.

I can find the CHART object and when you add a chart, Excel opens and defaults a data souce for the ppt chart (100% better, IMHO)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Mmm I have the following code which is pretty similar to the one posted previously except that this one deals with a powerpoint 2007 file, one benefit is that the macro does not produce run time errors but the big problem is that does not update the graph neither, checking it out step by step I found the code jumps from the line "If oPPTShape.OLEFormat.progID = "MSGraph.Chart.8" Then" to the first "end if" hence skipping the code part where instructed to do the paste, any ideas on how to solve the problem, thanks

Sub PPTX_CHART_UPDATE()
Dim objPPT As Object
Dim objPrs As Object
Dim objGraph As Object
Dim objDataSheet As Object
Dim rngData As Range
Dim intRow As Integer
Dim intCol As Integer

' excel dynamic named range
Set rngData = Range("Prices")
' open powerpoint 2007
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
' open existing pptx presentation
objPPT.Presentations.Open "C:\Documents and Settings\A3592413\Escritorio\Presentation1.pptx"
' chart on slide 1
Set objPrs = objPPT.Presentations(1).Slides(1)
' pointer to graph
Set objGraph = objPrs.Shapes(1).OLEFormat.Object.Application
' pointer to graphs data sheet
Set objDataSheet = objGraph.DataSheet
' transfer data
For intRow = 1 To rngData.Rows.Count
For intCol = 1 To rngData.Columns.Count
objDataSheet.Cells(intRow, intCol) = rngData.Cells(intRow, intCol)
Next
Next
' update charts and save changes in presentation
objGraph.Update
objGraph.Quit
objPPT.Presentations(1).Save
objPPT.Quit

Set rngData = Nothing
Set objGraph = Nothing
Set objDataSheet = Nothing
Set objPrs = Nothing
Set objPPT = Nothing

End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top