Search code examples
vbapowerpoint

I need a vba code for display a rgb color for selected shape in powerpoint


I am a new for ppt vba, before i using only word record macro

I need help to get a rgb color for selected shapes in powerpoint 2013 by vba code


Solution

  • This will get you started:

    Dim oSh As Shape
    For Each oSh In ActiveWindow.Selection.ShapeRange
        With oSh.Fill
            Debug.Print .ForeColor.RGB
        End With
    Next
    

    Here's a routine for converting the Long returned by .RGB above to the R, G, B components. You need to here:

    Sub LongColorToRGB(ByRef lRed As Long, _
        ByRef lGreen As Long, _
        ByRef lBlue As Long, _
        ByVal lRGBColor As Long)
    ' Note:  if long > 16777214, returns 255s for all three values
    ' Note:  be sure to dim your variables in the routine that
    '        calls this sub
    
    pRed = pRGBColor Mod 256
    pGreen = pRGBColor \ 256 Mod 256
    pBlue = pRGBColor \ 65536 Mod 256
    
    End Sub