+ Reply to Thread
Results 1 to 4 of 4

Macro for word font colour

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Macro for word font colour

    Hi Guys,

    I need a macro that goes through every line within a word document.

    when it hits font with a particular colour, it needs to insert a line with text, then searching down the document, until it meets a second colour and then also insert a line with text, and repeat.

    The document contains any type of fonts, but only about 4 or 5 colours. I am only interested in having a line inserted for the first change of occurance of each particular colours.

    eg (for Blue and Red):
    wfefd wefs
    efwd wad
    sefd wd a
    esfsefd waa wd
    sefww dw
    ewqd ddsf
    esfd wdd
    sef ww dad sa
    sefdwd adwd ad a


    would become:
    efwd wad
    sefd wd a
    esfsefd waa wd
    sefww dw
    ewqd ddsf
    esfd wdd
    sef ww dad sa
    sefdwd adwd ad a
    Thanks,

    JimmyWilliams

  2. #2
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Macro for word font colour

    *Bumping this thread.*

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    403

    Re: Macro for word font colour

    Hi Guys,

    I need a macro that goes through every line within a word document.

    when it hits font with a particular colour, it needs to insert a line with text, then searching down the document, until it meets a second colour and then also insert a line with text, and repeat.

    The document contains any type of fonts, but only about 4 or 5 colours. I am only interested in having a line inserted for the first change of occurance of each particular colours.

    eg (for Blue and Red):
    wfefd wefs
    efwd wad
    sefd wd a

    esfsefd waa wd
    sefww dw
    ewqd ddsf
    esfd wdd
    wadwad
    sef ww dad sa
    sefdwd adwd ad a
    redwda
    sefdwd adwd ad a
    sefdwd adwd ad a

    wfefd wefs
    sefdwd adwd ad a
    esfd wdd
    wfefd wefs
    wadwad

    would become:
    wfefd wefs
    Blue:
    efwd wad
    sefd wd a

    esfsefd waa wd
    sefww dw
    ewqd ddsf
    Red:
    esfd wdd
    wadwad
    sef ww dad sa
    Blue:
    sefdwd adwd ad a
    Red:
    redwda
    Blue:
    sefdwd adwd ad a
    sefdwd adwd ad a
    wfefd wefs
    sefdwd adwd ad a
    Red:
    esfd wdd
    wfefd wefs
    wadwad


    I hope that makes sense!
    Ideally I would like to be able to select what the two colours are, and also be able to customise the text inserted before each colour (eg "Red:" could be "Username A:" or "Serial NumberXXXX:")
    Last edited by JimmyWilliams; 07-08-2018 at 09:02 AM. Reason: This Post was added to make everything more clear.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro for word font colour

    You could use a macro like:
    Please Login or Register  to view this content.
    Note: The inserted text is the same colour as the found text. You can replace the colour names in StrTxt with your preferred strings, but all 17 'positions' in StrTxt must be filled regardless of whether there is a corresponding ColorIndex reference in the Select Case test. A slightly different approach would be required to have the inserted text in a different colour from the found text.
    Last edited by macropod; 07-09-2018 at 09:18 PM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 22
    Last Post: 12-29-2017, 01:19 PM
  2. [SOLVED] Macro failing at conditional formatting font colour
    By RC-AMG in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2015, 12:28 PM
  3. How do I format font colour by a certain word
    By mccartneyd1795 in forum Excel General
    Replies: 1
    Last Post: 07-28-2014, 06:01 AM
  4. [SOLVED] Excel macro- Find replace an itallic font word with a regular word?
    By thisisaboutwork in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2013, 01:48 PM
  5. Macro to clear only the contents of the cells which have a specific font colour
    By Stellakyp in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-05-2013, 11:01 AM
  6. Macro to control font colour
    By BeerKing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2011, 07:11 AM
  7. Changing Font Colour if cell is certain word?
    By wuming79 in forum Excel General
    Replies: 5
    Last Post: 07-11-2006, 10:27 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1