Consulting

Results 1 to 8 of 8

Thread: Bar Chart Column Colors

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    8
    Location

    Bar Chart Column Colors

    Hi,

    I searched through forum but could not find an answer for the following question of mine: I need to change colors of columns in a bar chart.

    Manually I do the following: Select chart, click edit chart object, select column 1, set color, select column 2, set color, select column 3, set color, then close edit chart object. What I need is: I will select chart, click macro and it will set different color for each column.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    See if this helps

    [vba]Sub ograph()
    Dim osld As Slide
    Dim oshp As Shape
    Dim ograph As Object
    For Each osld In ActivePresentation.Slides
    'Find the msGraph object
    For Each oshp In osld.Shapes
    If oshp.Type = msoEmbeddedOLEObject Then
    If oshp.OLEFormat.ProgID Like "MSGraph*" Then
    'it's a graph
    Set ograph = oshp.OLEFormat.Object
    'do something with it
    ograph.SeriesCollection(1).Interior.Color = RGB(255, 0, 0) 'red
    ograph.SeriesCollection(2).Interior.Color = RGB(0, 0, 255) 'blue
    End If 'it's an OLE object
    End If 'it's a graph

    Next oshp
    Next osld
    End Sub[/vba]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Jan 2009
    Posts
    5
    Location
    Hi John,

    Could you please help me out with a code which helps in changing the colours of only the active chart rather than changing the colours of all the charts present in the active slide of the PPT.

    The above code changes the colours of all the charts present in the active slide.

    Awaiting for a quick and positive response.
    Thanks in advance
    Delvi

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    If you mean the selected graph maybe this will help

    [VBA] Dim osld As Slide
    Dim oshp As Shape
    Dim ograph As Object
    Set osld = ActiveWindow.View.Slide
    'Check the msGraph object
    Set oshp = ActiveWindow.Selection.ShapeRange(1)
    If oshp.Type = msoEmbeddedOLEObject Then
    If oshp.OLEFormat.ProgID Like "MSGraph*" Then
    'it's a graph
    Set ograph = oshp.OLEFormat.Object
    'do something with it
    ograph.SeriesCollection(1).Interior.Color = RGB(255, 0, 0) 'red
    ograph.SeriesCollection(2).Interior.Color = RGB(0, 0, 255) 'blue
    End If 'it's an OLE object
    End If 'it's a graph[/VBA]
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    Dec 2008
    Posts
    8
    Location
    That is what I am looking for! This macro will save hours.

    Thanks a lot

  6. #6
    VBAX Regular
    Joined
    Dec 2008
    Posts
    8
    Location
    I have a new problem related to this one: I cannot set any color I want. For example, when I put RGB(187, 224, 227) into code, chart color becomes a slightly different color. Original one is close to blue, what I get is close to grey.

  7. #7
    VBAX Contributor
    Joined
    May 2008
    Posts
    198
    Location
    Charts are limited to a small pallete of colors, you don't have the entire RGB range available, so it's probably selecting the closest to the color you picked.

  8. #8
    VBAX Regular
    Joined
    Dec 2008
    Posts
    8
    Location
    Yes, that is what it does, selecing the closest color.
    But when I set colors from master slide --> edit color scheme, it applies any color I want to charts. Why it fails with macro? Is there a way to set any RGB color I want with macro?

Posting Permissions

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