Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA charting (VBA/Powerpoint(MSGraph)/2000)

    Hey everyone.

    Can anyone point me in the direction of where to get some basic information (unless people know here) on controlling MSGraph from VBA. At the moment, i'm just wanting to create the simplest of pie charts (4 equal segments) as well as control the colour palette in MSGraph as I need specific colours that aren't in the slide colour scheme. Does excel vba charting code bare any resemblance/or be of help in a PPT environment? If this is enormously complicated, would it be better to have the charts I require pre-built in a hidden presentation and copy them from there using code?

    Many thanks

    Thom

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: VBA charting (VBA/Powerpoint(MSGraph)/2000)

    You can manipulate MSGraph charts in code if you set a reference to the Microsoft Graph 9.0 Object Library in Tools | References. The object model closely resembles that of charts in Excel. you can use the Object Browser (F2) and the built-in help (F1) to get help on Graph objects.

    If I need to program MSGraph, I usually record, edit and test the code in Excel first, then adapt it for MSGraph.

    An example can be found in How To Automate An Embedded MSGraph Object with Visual Basic (it is for Word, but the chart code wil work in PowerPoint too).

  3. #3
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA charting (VBA/Powerpoint(MSGraph)/2000)

    Thanks Hans.

    I'm taking a look at this now, and trying to work it out.

    I've comeup with:-

    Sub GraphTest()
    Dim oShape As PowerPoint.Shape
    Dim oGraphChart As Graph.Application


    ActiveWindow.Selection.SlideRange.Shapes.AddOLEObj ect(Left:=120#, _
    Top:=110#, Width:=480#, Height:=320#, ClassName:="MSGraph.Chart.8", Link:=msoFalse).Select
    ActiveWindow.Selection.ShapeRange.OLEFormat.Activa te
    With ActiveWindow.Selection.ShapeRange
    .Left = 120#
    .Top = 109.875
    .Width = 480#
    .Height = 320.25
    End With
    Set oGraphChart = oShape.OLEFormat.Object

    With oGraphChart
    .ChartArea.Font.Size = 8
    .Application.Update
    End With

    ActiveWindow.Selection.Unselect
    End Sub

    so far, but it's falling over on the .ChartArea.Font.Size = 8 line, and I'm not too sure why!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: VBA charting (VBA/Powerpoint(MSGraph)/2000)

    I don't see where you define oShape in your code.
    oGraphChart is an object of type Graph.Application. To do something with the chart, you must use its Chart property:

    Sub GraphTest()
    Dim oShape As PowerPoint.Shape
    Dim oGraphChart As Graph.Application

    Set oShape = ActiveWindow.Selection.SlideRange.Shapes.AddOLEObj ect _
    (Left:=120#, Top:=110#, Width:=480#, Height:=320#, _
    ClassName:="MSGraph.Chart.8", Link:=msoFalse)

    oShape.OLEFormat.Activate
    Set oGraphChart = oShape.OLEFormat.Object.Application
    With oGraphChart
    .Chart.ChartArea.Font.Size = 8
    .Update
    .Quit
    End With

    ActiveWindow.Selection.Unselect
    End Sub

  5. #5
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA charting (VBA/Powerpoint(MSGraph)/2000)

    Ahhh. I see.

    Thanks again Hans, You've set me on my way.

    Take care

Posting Permissions

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