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

    Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    I was wondering if it is possible to change the RGB values of the color index in powerpoint with VBA for MSGRAPH. Obviously it's possible manuallly through "options" when a chart is active, but I want these values set when my code creates the chart?

    Many thanks in advance.

    Thom

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Yes, that is possible, but the exact details depend on what you already have and what you want. Say that you have created a shape oPPTShape. The code

    Dim oGraph As Graph.Chart
    Set oGraph = oPPTShape.OLEFormat.Object
    oGraph.SeriesCollection(1).Interior.ColorIndex = 3

    sets the fill color for the first series to red.

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Thanks Hans.

    Its possible, manually, when you created a chart and have double clicked into it, to select "tools" then "options" and goto the Color tab. here, one can manually change the RGB values of the color index. This is idealy what i'd like to be able to do using code and then referring to the color index by number. (it can be done in excel!)

    The reason is, that when you create a new chart , powerpoint reverts back to it's default color index!. Though if you copy a chart where you've already changed the color index, it remembers it.

    ideally I'm trying to avoid having a hidden file somewhere with all the required charts and colors updated in the index, and instead build the whole thing with Code, which i can now do, apart from the colors.

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    I see that I misread your question (I was too hasty)

    SammyB pointed out this newsgroup thread (thanks, Sam!).

  6. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    I'm afraid I don't know how to do that - I tried some code that ran without an error, but all it did was reset the colors to their factory set defaults.

  7. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 15 Times in 15 Posts

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    SammyB suggests the following (thanks again, Sam!):

    Not really, there are only 56 predefined colors, the manual process lets you think that you can make any color, but it chooses the closest one in the list of 56. Try changing the color, note the RGB values, close out of the chart, then come back in. The RGB values will have changed to one of the 56. See Excel code to modify Excel chart palette colors so you can create a palette with both the colors and the colorindex's listed. Then, you can use Hans's code "oGraph.SeriesCollection(1).Interior.ColorInde x = 3" replacing the 3 with the color that you want to use.

  8. #7
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Well, you-all don't seem to be able to function without me, so I've crawled out from behind the stupid firewall. <img src=/S/drop.gif border=0 alt=drop width=23 height=23>
    Is this what you had in mind? Remember, 3 is is one of the 56 colors that I've been whining about above. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> HTH --Sam
    <pre>Sub TestData()

    Dim ppSlide As Slide
    Dim ppChart As Shape

    Set ppSlide = ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)
    ActiveWindow.View.GotoSlide ppSlide.SlideNumber
    Set ppChart = ppSlide.Shapes.AddOLEObject(Left:=120, Top:=140, Width:=480, _
    Height:=320, ClassName:="MSGraph.Chart", Link:=msoFalse)
    With ppChart
    .OLEFormat.Activate
    With .OLEFormat.Object
    .HasTitle = True
    .ChartTitle.Text = "Demo Red Chart"
    With .Application.DataSheet
    .Cells.Clear
    .Cells(1, 2) = "Jan"
    .Cells(1, 3) = "Feb"
    .Cells(2, 1) = "OH"
    .Cells(2, 2) = 10
    .Cells(2, 3) = 20
    .Cells(3, 1) = "IN"
    .Cells(3, 2) = 15
    .Cells(3, 3) = 20
    End With
    .SeriesCollection(1).interior.colorindex = 3
    End With
    End With
    ActiveWindow.Selection.Unselect
    Set ppChart = Nothing
    Set ppSlide = Nothing
    End Sub
    </pre>

    <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>

  9. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    BTW, if you happen to have the data in Excel and you still want to use MSGraph, you can import the data directly:
    <pre>Sub TestImport()

    Dim ppSlide As Slide
    Dim ppChart As Shape

    Set ppSlide = ActivePresentation.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)
    ActiveWindow.View.GotoSlide ppSlide.SlideNumber
    Set ppChart = ppSlide.Shapes.AddOLEObject(Left:=120, Top:=140, Width:=480, _
    Height:=320, ClassName:="MSGraph.Chart", Link:=msoFalse)
    With ppChart
    .OLEFormat.Activate
    With .OLEFormat.Object
    .HasTitle = True
    .ChartTitle.Text = "File Chart"
    .Application.FileImport "c:demo.xls"
    End With
    End With
    ActiveWindow.Selection.Unselect
    Set ppChart = Nothing
    Set ppSlide = Nothing
    End Sub
    </pre>

    <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>

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Thanks for this everyone. Just got into work, so i'm going to have a good look through all this, and let you know how it goes.

    p.s., apparently ActiveChart.Colors(5) = RGB(255, 0, 0) is supposed to work, but I think that's just for 2003!

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Thanks everyone.

    Sammy. if you look at the chart i've attached, and double click into it and look at the colors, these are the colours that i'm wanting to create with VBA (the main index). when done manually, they do seem to stick, even when you click in and out of the chart. (NB, I've set the "Recolor Chart" to "none"). At the moment, i've set it up to import this chart from a hidden file, then do all it's stuff to it. i.e.

    .Chart.SeriesCollection(1).Points(1).Interior.Colo rIndex = 9
    .Chart.SeriesCollection(1).Points(2).Interior.Colo rIndex = 3 and so on

    This then assigns the two predefined blues.

    The only drawback with all this, is that it's it won't work on an existing chart that the user has imported.

  12. #11
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Boy, I hate MSGraph. I cannot get the colors quite right, but here's some Info for you.

    First, sorry for the link to the Excel code: it was crazy. But, starting with some of the information there, I created the attached workbook with the color indices and the colors. I then matched your colors with the "standard" colors. I could not do a very good matching job. I apologize for saying that you cannot manually change them: you obviously did!

    Second, I modified my PP code to create a pie chart. It is included below. There is sill some coding to do to make it look like yours. The documentation for MSGraph is at http://"]http://msdn.microsoft.com/library/default....e=true">http:// http://msdn.microsoft.com/library/default.....asp?frame=true[/url]. It, of course, says that you can use the Colors property to set the palette, but it doesn
    <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>

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

    Re: Programmatically Change the color index (VBA/Powerpoint(MSGraph)/2000)

    Thanks again for Sammy.

    I know what you mean about MSGraph. Searching for any information on it is hard, and is often prefixed with "I hate MSGraph".

    I think i'm going to wait till we migrate to 2003 before delving to much deeper into it.

    For the time being i've created a hidden file that gets imported then I'm manipulating it from there, so the code you

Posting Permissions

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