+ Reply to Thread
Results 1 to 5 of 5

VBA code required to colour text

  1. #1
    Forum Contributor
    Join Date
    10-19-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    146

    VBA code required to colour text

    Hi,

    I have a problem that I hope someone will be able to help with.

    I have a Word document template that mail merges from a spreadsheet. This works fine.

    My problem is that I need to format the colour of some of the text in the mail merged document. I could format the text in the correct colour manually but there are 100's of recipients and it would be very time consuming.

    The text in the spreadsheet is formatted in the correct colour but when I mail merge, the text defaults to black.

    Would I need to write some VBA code in the excel spreadsheet to deal with this or does the text need to reformatted somehow in the completed mail merge document using code?

    I can attach some dummy data in a spreadsheet with the document template if this helps.

    Thanks for looking.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    582

    Re: VBA code required to colour text

    Hi cosmica67,

    Maybe not the direct answer, but a 'work-around' which may does the trick...

    If the formatting applies to the full merged field, and there are not too many different versions of that field, you could split the data into multiple columns in your source data.
    Example; You want to color the name in either red, green or blue based on whatever criteria.
    Insert the name in 3 columns with headings like 'Name-red', 'Name-green', 'Name-blue' etc.. Enter the names in the corresponding columns (copy all for all 3 columns, use filter by color to remove the once not matching the heading..).
    In the merge document where you want the name, insert all 3 fields without any space between.
    Format each of the fields as desired (red, green or blue) in the word document.
    When you then merge the fields, there will only one field have data in the source field, therefore only one will have the name and show formatted in the desired color.

    If the color formatting is for only part of the merge field, or it is not possible to adapt the source document, then someone else may be able to provide another solution.
    If your Question is answered; please mark it SOLVED. If you are happy with a member's solution, say 'Thanks' and click the 'Star' to Add Reputation.

  3. #3
    Forum Contributor
    Join Date
    10-19-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    146

    Re: VBA code required to colour text

    Many thanks for your reply.

    I will have a go at this suggestion.

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

    Re: VBA code required to colour text

    Quote Originally Posted by cosmica67 View Post
    I have a Word document template that mail merges from a spreadsheet. This works fine.

    My problem is that I need to format the colour of some of the text in the mail merged document. I could format the text in the correct colour manually but there are 100's of recipients and it would be very time consuming.
    Mailmerges only see the data, not font attributes. Depending on what rules determine the colouring in the source data, it might be possible to use field coding in the Word document to replicate the source colours. See the relevant discussions in the Mailmerge Tips & Tricks thread at: https://www.msofficeforums.com/mail-...ps-tricks.html
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    Forum Contributor
    Join Date
    10-19-2016
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    146

    Re: VBA code required to colour text

    Thanks, macropod.

    Will definitely have a look.

+ 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. Amendment in code required to populate new sheets with colour
    By User3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2017, 02:35 AM
  2. Code Required for Entire column text to one cell
    By structo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-31-2016, 10:30 AM
  3. Code required to open files - Excel,Word,Text,PDF
    By bimmy80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-04-2015, 01:36 AM
  4. [SOLVED] Simple Conditional Formating Help Required - If Blank then Red Bold text required
    By thilag in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-19-2014, 12:23 PM
  5. Replies: 1
    Last Post: 09-10-2013, 10:28 PM
  6. code to change text colour
    By n1k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-21-2008, 12:35 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