Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Word RGB Color Finder - Export Strings and RGB Colors

    Hi to all,

    I have a list of strings in various word documents.

    they are all a different color.

    Apples
    Bananas
    Grapes
    Cauliflower



    I was wondering if there is a way for me to make a report of the RGB colors of the string.

    Apples | RGB (0,176,80)

    Bananas | RGB(91,155,233)

    etc

    I am doing this manually and its not very effective as I have a lot of docs and strings in each one to get through.

    I was thinking would it would be possible to export these strings and RGB values to a table.

    I found this

    http://answers.microsoft.com/en-us/o...dd19feaed?db=5

    But I don't understand how to code it in vba as I have very limited vba experience.


    Or if any one could point me in the direction of a solution I will be grateful.

    thank you very much for your help

    pb

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    It seems to me you have a bit of a catch-22 situation here. Unless you know the colours in use, you can't search for strings containing them; unless you know which strings are coloured, you can't search for them and find out what colours they're using. Searching all 16,77,7216 possible colour combinations isn't feasible so, unless you know either the colours or the strings, what you'd be left with is testing each word in the document to see what colour is uses. And, if a given word uses more than one colour, ...
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hi Paul,

    aah that's a shame, I can't simply ask word to look for words that have a color applied to them, I suppose that's what you are saying.

    I was thinking it would be similar to a style report - where it lists all the the styles in use in a document, but instead font colors.

    if text.font.color = " some wildcard RGB Value " or

    Selection.Font.TextColor.RGB > 0 to start off with

    Or should I look at the xml sheet some how - where it has font runs, but that's even more complex.

    thank you

    pb

  4. #4
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    PB:

    I'm not very familiar with Visual Basic, but it seems to me that the way you could proceed is to write some VB code which would scan through an entire document, character by character, and then output the RGB values for that character into a text file. Using your original post above as an example, the text file output would look something like this:

    W 0 0 0
    o 0 0 0
    r 0 0 0
    d 0 0 0

    R 0 0 0
    G 0 0 0
    B 0 0 0
    .
    .
    .
    A 0 176 80
    p 0 176 80
    p 0 176 80
    l 0 176 80
    e 0 176 80
    s 0 176 80

    B 91 155 233
    a 91 155 233
    n 91 155 233
    a 91 155 233
    n 91 155 233
    a 91 155 233
    s 91 155 233
    .
    .
    .

    I don't believe it would be that difficult to do this, if you had the formula to return the RGB values for each character.
    Basically, your VB code would open the text file, output all of the lines of text into the text file, then close the text file.
    Each line in the text file would contain the character, the RGB values, and a carriage return and line feed at the end of the line:
    char space R-value space G-value space B-value carriage-return line-feed

    Jim
    Last edited by mrjimphelps; 2016-01-29 at 10:35.

  5. #5
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hi Jim,

    I would not mind this method ..

    So I should search for a RGB character vba macro to get me started.

    I suppose I could extract the values to excel and clean it up to get the ones I need

    In excel its easy to find the cell RGB color - I wish it was easy in word


    thank you

    pb

  6. #6
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    Quote Originally Posted by pb89 View Post
    I suppose I could extract the values to excel and clean it up to get the ones I need
    I think your life will be a lot easier if you just write the data to a text file.

    Once the file is complete, you can easily open it in Excel and do your cleanup.

    Sorry that I don't know a formula or macro to give you. I haven't done any programming in decades, and when I did, it was never in any version of Basic.

  7. #7
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    Here is something which might be helpful:
    https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx

  8. #8
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by pb89 View Post
    aah that's a shame, I can't simply ask word to look for words that have a color applied to them, I suppose that's what you are saying.
    Close, but not exactly. Everything has a colour (unless you want to be picky and say black isn't a colour); otherwise you couldn't see it. That said, you could use Find/Replace to hide or delete everything that's black; what's left would be all the content in other colours.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  9. #9
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hi Jim & Paul,

    thanks for the pointers. I over projected the ease of finding some simple RGB colors.


    I will dig about and see if I can put some thing together.

    I may just try to find a simple function - and then select the text - that would print the RGB color - even that would be better than nothing.

    It's really hard to read the word RGB palette , when using the color picker to see what RGB value of a given text is.

    One absolutely annoying feature is the RGB pallete will not minimise - you cant also copy and paste the values.

    I tend to forget the values and have to double and triple check some times .

    The other option is - If I put some identifiers in front of the strings would that make it easier for an RGB macro? Would it be able to identify the RGB color used in that string?

    thank you

    pb

  10. #10
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by pb89 View Post
    I tend to forget the values and have to double and triple check some times .

    The other option is - If I put some identifiers in front of the strings would that make it easier for an RGB macro? Would it be able to identify the RGB color used in that string
    You do realise that the colour palette displays your 'Recent colours' below the std set?

    Sure, if you prefix the coloured strings with a tag, a wildcard Find could be used to locate them - even better if both ends of each coloured string are tagged.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  11. #11
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Hello Paul,

    I have had the good fortune of finding this macro you wrote

    http://www.msofficeforums.com/word-v...nt-colors.html


    It would be great if I am able to do the opposite now split the text color into RGB

    Code:
    Sub FindRGBColors()
    
    
    
    Dim i As Long, R As Long, G As Long, B As Long, Rng As Range
    Dim RngRed As Long
    
    With ActiveDocument.Tables(1)
      For i = 2 To .Rows.Count
      
        
        .Cell(i, 5).Range.Font.TextColor = RGB(R, G, B)
        'Split this Cell Color - An Array?
        
        
        Set Rng = .Cell(i, 1).Range
        
        RngRed = CLng(Rng.Text)
        
        
        Rng.End = Rng.End - 1
        
        R = CLng(Rng.Text)
        Set Rng = .Cell(i, 2).Range
      
        
        
        G = CLng(Rng.Text)
        Set Rng = .Cell(i, 3).Range
       
        
        
        B = CLng(Rng.Text)
        
        
      Next i
    End With
    
    'http://www.msofficeforums.com/word-vba/17512-help-macro-set-font-colors.html
    End Sub
    any help much appreciated

    thank you

    pb

  12. #12
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Try:
    Code:
    Sub FindRGBColors()
    Application.ScreenUpdating = False
    Dim i As Long, Rng As Range
    With ActiveDocument.Tables(1)
      For i = 2 To .Rows.Count
        Set Rng = .Cell(i, 1).Range
        Rng.End = Rng.End - 1
        'Red
        .Cell(i, 2).Range.Text = Rng.Font.Color \ 256 ^ 0 Mod 256
        'Green
        .Cell(i, 3).Range.Text = Rng.Font.Color \ 256 ^ 1 Mod 256
        'Blue
        .Cell(i, 4).Range.Text = Rng.Font.Color \ 256 ^ 2 Mod 256
      Next i
    End With
    Application.ScreenUpdating = True
    End Sub
    The text to be tested goes in the first column; columns 2-4 report the RGB values.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  13. The Following User Says Thank You to macropod For This Useful Post:

    pb89 (2016-01-31)

  14. #13
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Smile Solved

    Hello Paul,

    I was about to give up, just couldn't work out and put the code in order - seems simple but not with my lack of experience with VBA.


    but wow This is great!!

    Code:
     .Cell(i, 2).Range.Text = Rng.Font.Color \ 256 ^ 0 Mod 256
    I did not know you could divide a range with the Mod 256 as above.


    Thank you ever so much

    Thanks for being a Champion -

    I am happy to copy the words in a table and then get the values -
    its better than individually using the Color pallet > more colors > custom - then forgetting half the values

    This is solved thank you for helping me

    pb

  15. #14
    WS Lounge VIP mrjimphelps's Avatar
    Join Date
    Dec 2009
    Location
    USA
    Posts
    3,396
    Thanks
    445
    Thanked 404 Times in 376 Posts
    PB -- in division, "MOD" means "Modulus" or "remainder", and "/" means "Division". In plain English, that means that when you divide using the MOD operator rather than the "/" operator, you get the remainder rather than the quotient. Since there are 256 possible values (0 to 255) in the RGB table for each of the three primary colors, if you MOD by 256, you will get a number which is meaningful to the RGB table, i.e., your answer will be somewhere between 0 and 255.
    Last edited by mrjimphelps; 2016-02-01 at 08:34.

  16. #15
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    That will keep them RGB colors in check Jim,

    I will know when the colors are trying to HEX me

  17. The Following User Says Thank You to pb89 For This Useful Post:

    mrjimphelps (2016-02-01)

Page 1 of 2 12 LastLast

Posting Permissions

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