Results 1 to 2 of 2
2001-07-09, 10:13 #1SparkyTGuest
PPT2000 & MSGraph Automation (PPT2000, MSGraph, VBA)
I am attempting to generate charts using the msgraph control that powerpoint uses for its charts. For various reasons I do not wish to embed excel charts in the ppt slides. Once I have created the charts using vba, I come up against a major irritation.
Once the charts exist, if the presentation is then saved and re-opened, activating the charts reverts them to their original example data rather than the data I have added. If before saving, the charts are individually activated and de-activated, subsequent re-opening and activation will not reset the data in them.
To see this in action, run the enclosed code from ppt2000 to produce a chart, save the resulting presentation, close and re-open it, then activate the chart by double clicking on it. If all goes well the chart data should change back to the original example data. I am currently running plain O2k with no service releases installed, if this is solved with any of the service packs, please let me know and I'll enter the long fight to get updated.
Code enclosed below, adapted from example on http://support.microsoft.com/support/kb/ar...s/Q222/6/87.ASP
Dim oGraph As Object
Dim oDataSheet As Object
Dim shpGraph As PowerPoint.Shape
Dim lRowCnt As Long
Dim lColCnt As Long
Dim lValue As Long
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutBlank).SlideIndex
' Add the graph to the slide.
' Create the Graph object on the slide.
Set shpGraph = .Shapes.AddOLEObject(ClassName:="MSGraph.Chart", Link:=msoFalse)
' Set references.
Set oGraph = shpGraph.OLEFormat.Object
Set oDataSheet = oGraph.Application.DataSheet
' Place headers into data table.
' Create four column headers.
oDataSheet.Cells(1, 2).Value = "Col1"
oDataSheet.Cells(1, 3).Value = "Col2"
oDataSheet.Cells(1, 4).Value = "Col3"
oDataSheet.Cells(1, 5).Value = "Col4"
' Create four row headers.
oDataSheet.Cells(2, 1).Value = "Row1"
oDataSheet.Cells(3, 1).Value = "Row2"
oDataSheet.Cells(4, 1).Value = "Row3"
oDataSheet.Cells(5, 1).Value = "Row4"
' Set four rows of data.
For lRowCnt = 2 To 10
For lColCnt = 2 To 5
' Place in data table.
oDataSheet.Cells(lRowCnt, lColCnt).Value = lRowCnt * lColCnt
' Release the reference.
Set oGraph = Nothing
Set oDataSheet = Nothing
2001-07-09, 11:43 #2
- Join Date
- Mar 2001
- Springfield, Ohio, USA
- Thanked 1 Time in 1 Post
Re: PPT2000 & MSGraph Automation (PPT2000, MSGraph, VBA)
Tim, I followed your instructions, but it worked perfectly. Your code looks correct to me. <A target="_blank" HREF=http://groups.google.com/groups?hl=en&safe=off&ic=1&th=7fb617fc3317e156,5&s eekm=38F675F48B36D4118E4D00508B5EBA37023B9D21@cpms ftmsgv21.microsoft.com#p>Here</A> is another example which uses MSGraph. I'm currently using PP2K (9.0.2716). Looks like you need to <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15> upgrade. --Sam<font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
<small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>