Consulting

Results 1 to 9 of 9

Thread: RGB values from COlor Themes via VBA

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location

    RGB values from COlor Themes via VBA

    Hello, It's my first post and I'm completely new to VBA. I'm trying to copy Accent RGB values into textbox on slide in PowerPoint

     
    Shape.Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent1
    Shape.TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)    
    Shape.TextFrame.TextRange.Characters.Text = msoThemeColorAccent1
    It fills shape color with Accent 1, but as I supposed returns only position of Accent 1 which is 5... is there a way to return RGB values.. so the result would be sth like A1: 123 144 156

    Thank you for your time and help.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Try this


    Option Explicit
    
    Sub test()
        
        Dim N As Long, R As Long, G As Long, B As Long
    
        With ActivePresentation.Slides(1).Shapes(1)
    
            .Fill.ForeColor.ObjectThemeColor = msoThemeColorAccent1
            .TextFrame.TextRange.Font.Color.RGB = RGB(255, 255, 255)
            N = .Fill.ForeColor.RGB
            
            B = N \ 65536
            G = (N - B * 65536) \ 256
            R = N - B * 65536 - G * 256
    
            .TextFrame.TextRange.Characters.Text = "R:" & R & " G:" & G & " B:" & B
    
        End With
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    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

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    Thank you very much Now it works! Great job

  4. #4
    This will work fine with standard colors and RGB colors but if theme color used means it will not work. How to find the RGB value for theme colors

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    It will work for theme colours so maybe explain exactly what you mean.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    This works fine if the text is one of the standard colors OR even a custom color from the RGB color-picker, but it will return nagative long value -738148353 if the text color is one of those in the "theme colors" in Font Color dialog. If you use standard color you can get long value and convert into RGB but if theme color used then you will get negative long value and so you can't able to convert into RGB. It will give wrong RGB value If you try to convert those negative long value.

    Please refere my attachement.

    RGB.jpg

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I cannot read the code you posted for sure but it looks like WORD not PowerPoint and it looks incorrect

    The correct code would be ?Selection.Font.Fill.Forecolor.RGB because in recent versions the selection is TextRange2
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    Yes, WORD but it not a big deal. Color always colors where ever we use. My point is if you use theme colors then you can't get the correct RGB value. Because your will get negative value only so, you cant convert those values with your code to get the RGB.

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    My point is you code is not correct hence the negative value for later versions of word. Use the code I provided above and you should get the correct value.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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