none
Text.Font.Color Property in VBA for PowerPoint RRS feed

  • Question

  • Hello,

    I'm trying to return the color of a piece of text in a PowerPoint slide and then use that color for other texts throughout the presentation, as needed.  When I return the color using the code below, it provides only a singe number, rather than the 3 numbers of the RGB index (i.e. RGB(255, 0, 0)).  For instance, tx3 RGB = 5296274, and I'm not sure how to use this number to set the font color of other texts throughout.  Any advice much appreciated - please keep in mind I'm new to VBA.  Thanks!

    Sub FindtxtColor()
        Dim sl As Slide
        Dim sh As Shape
        Dim tx As TextRange
        Dim tx2 As TextRange
        Dim tx3 As TextRange    
        
        For Each sl In ActivePresentation.Slides
            If sl.SlideID = 1245 Then
                For Each sh In sl.Shapes
                    If sh.HasTextFrame = msoTrue Then
                        Set tx = sh.TextFrame.TextRange
                        Set tx2 = tx.Find(FindWhat:="Lower")
                        Set tx3 = tx.Find(FindWhat:="Higher")
                        MsgBox tx2 & " " & tx2.Font.Color.RGB
                        MsgBox tx3 & " " & tx3.Font.Color.RGB
                    End If
                Next sh
            End If
        Next
               
    End Sub

    Tuesday, September 4, 2012 6:10 PM

All replies

  • Powerpoint will adjust.You need not worry.

    You can use directly

    tx2.Font.Color.RGB=tx3.Font.Color.RGB

    or by assugning to some avriable,then assigning from that variable.


    Best Regards,
    Asadulla Javed, Kolkata
    ---------------------------------------------------------------------------------------------
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Wednesday, September 5, 2012 10:48 AM
    Answerer
  • Internally, an RGB value is always only a single number, I believe a 32-bit (4-byte) Long.  The two least-significant bytes are the Red value, the next two least-significant bytes are the Green value, and the next two are the Blue value.

    So, for example, the RGB color represented by RGB(57,199,84), a random shade of green, would return the Long value 5,556,025.  This has the hexadecimal equivalent of &H54C739; the Red value is thus &H39, the Green is &HC7, and the Blue is &H54.  In decimal, that's Red=57, Green=199, Blue=84, just as expected.

    To note, I believe the two most-significant bytes are unused in the VBA RGB specification. Also important: this manner of constructing RGB colors is Windows-specific -- the color scheme is different on Macs.

    Wednesday, September 5, 2012 2:04 PM
  • You can use standard named color, like: vbRed

    For change color you can use this code

    Sub zmiana_koloru_w_PPS()
    'MVP OShon from VBATools.pl
    Dim shp As Shape, sl&
    For sl = 1 To ActivePresentation.Slides.Count
     For Each shp In ActivePresentation.Slides(sl).Shapes
     On Error Resume Next
     Debug.Print shp.TextFrame.TextRange.Font.Color.RGB 'oryginal colour
     shp.TextFrame.TextRange.Font.Color = vbRed 'we're use this name for each shapes in PP
     Next
    Next sl
    End Sub

    also this named is for use

    vbBlack 0x0 Black
    vbRed 0xFF Red
    vbGreen 0xFF00 Green
    vbYellow 0xFFFF Yellow
    vbBlue 0xFF0000 Blue
    vbMagenta 0xFF00FF Magenta
    vbCyan 0xFFFF00 Cyan
    vbWhite 0xFFFFFF White


    Oskar Shon, Office System MVP

    Press if Helpful; Answer when a problem solved

    Thursday, September 6, 2012 8:01 AM
    Answerer