Consulting

Results 1 to 2 of 2

Thread: Color chart caption with VBA

  1. #1

    Post Color chart caption with VBA

    Hi guys.

    I posted a question in Excel Help and problem was fixed. My problem now is how I can adapt this macro to PowerPoint.

    I attached my excel in this thread. ChartColour.xlsm

    I need create a PowerPoint file with this graphs and I would like use this macro in PowerPoint to set up colors of series graphs.

    I really appreciate your help.

    Tks

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Not very elegant and could use some error checking


    Option Explicit
    Sub ApplyColors()
    
        Dim oSlide As Slide
        Dim oShape As Shape
        Dim oChart As Chart
        Dim oSeries As Series
        Dim v As Variant
        Dim iSeries As Long
        
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                Set oChart = Nothing
                On Error Resume Next
                Set oChart = oShape.Chart
                On Error GoTo 0
                
                If Not oChart Is Nothing Then
                    For iSeries = 1 To oChart.SeriesCollection.Count
                        v = Split(oChart.SeriesCollection(iSeries).Name, " ")
                        oChart.SeriesCollection(iSeries).Interior.Color = Name2Color(CStr(v(0)))
                    Next iSeries
                End If
            Next
        Next
    End Sub
     
    
    Function Name2Color(s As String) As Long
        Select Case s
            Case "Bárbara": Name2Color = RGB(102, 0, 102)
            Case "Bruna": Name2Color = RGB(49, 133, 156)
            Case "Cassiano": Name2Color = RGB(55, 96, 146)
            Case "Daniele": Name2Color = RGB(0, 0, 0)
            Case "Fabio": Name2Color = RGB(255, 235, 158)
            Case "Fernando": Name2Color = RGB(255, 255, 0)
            Case "Guilherme": Name2Color = RGB(127, 127, 127)
            Case "Gustavo": Name2Color = RGB(155, 187, 89)
            Case "Henrique": Name2Color = RGB(204, 193, 218)
            Case "Jorge": Name2Color = RGB(33, 89, 104)
            Case "Julio": Name2Color = RGB(195, 214, 155)
            Case "Leandro": Name2Color = RGB(64, 49, 82)
            Case "Lucas": Name2Color = RGB(119, 147, 60)
            Case "Luiza": Name2Color = RGB(123, 123, 123)
            Case "Pedro": Name2Color = RGB(1, 13, 255)
            Case "Priscilla": Name2Color = RGB(204, 51, 0)
            Case "Sergio": Name2Color = RGB(152, 72, 7)
        End Select
    End Function
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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