Results 1 to 2 of 2
  1. #1

    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.

    Many thanks


    Code enclosed below, adapted from example on

    Sub CreateGraph()

    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

    Presentations.Add WithWindow:=msoTrue
    ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutBlank).SlideIndex

    ' Add the graph to the slide.
    With ActivePresentation.Slides(1)
    ' Create the Graph object on the slide.
    Set shpGraph = .Shapes.AddOLEObject(ClassName:="MSGraph.Chart", Link:=msoFalse)
    End With

    ' 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
    Next lColCnt
    Next lRowCnt

    ' Release the reference.
    Set oGraph = Nothing
    Set oDataSheet = Nothing

    End Sub

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Springfield, Ohio, USA
    Thanked 2 Times in 2 Posts

    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=,5&s eekm=38F675F48B36D4118E4D00508B5EBA37023B9D21@cpms>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>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts