Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2019, 01:15 AM
Colin Vicary Colin Vicary is offline Text Background Colour in a Table Windows 10 Text Background Colour in a Table Office 2016
Novice
Text Background Colour in a Table
 
Join Date: Aug 2019
Posts: 3
Colin Vicary is on a distinguished road
Default Text Background Colour in a Table

Hi everyone, I'm new here so please be gentle with me!

I am creating a mail merge document, I've not posted in mail merge though, as this seems to be a more basic formatting question.

I have given my page a background colour, and for every cell in the table the text is black with the grey background colour, apart from one cell in each table! This cell has a white text background.

I've attached the document here, can anyone please help me colour this one cell?

Thanks in advance



Colin
Attached Files
File Type: doc Promo Template.doc (401.5 KB, 7 views)
Reply With Quote
  #2  
Old 08-08-2019, 02:02 AM
gmayor's Avatar
gmayor gmayor is offline Text Background Colour in a Table Windows 10 Text Background Colour in a Table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you mean in the merge document itself then the following macro will do that.

Code:
Sub Macro1()
Dim oCell As Cell
Dim oFld As Field
    For Each oCell In ActiveDocument.Tables(1).Range.Cells
        For Each oFld In oCell.Range.Fields
            If oFld.Type = wdFieldMergeField Then
                If InStr(1, oFld.Code, "Product") > 0 Or _
                   InStr(1, oFld.Code, "Desc") > 0 Then
                    oCell.Shading.BackgroundPatternColor = wdColorWhite
                    Exit For
                Else
                    oCell.Shading.BackgroundPatternColor = &HD9D9D9
                End If
            End If
        Next oFld
    Next oCell
lbl_Exit:
    Set oCell = Nothing
    Set oFld = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 08-08-2019, 03:09 AM
Colin Vicary Colin Vicary is offline Text Background Colour in a Table Windows 10 Text Background Colour in a Table Office 2016
Novice
Text Background Colour in a Table
 
Join Date: Aug 2019
Posts: 3
Colin Vicary is on a distinguished road
Default

Hi Graham

Thanks for spending the time on this, it has really helped me to understand how the macros work in Word.

I stepped through the macro to see how it worked and followed the logic - a real eye opener.

However, although the cell has been coloured, the text still has a white background, whereas all the other text in the document uses the grey cell colour as a background - can you see that?

What code can I add to fix that please?

Thanks

Colin
Reply With Quote
  #4  
Old 08-08-2019, 04:38 AM
gmayor's Avatar
gmayor gmayor is offline Text Background Colour in a Table Windows 10 Text Background Colour in a Table Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

I hadn't noticed that, but actually it has a light grey background. It is easily addressed. After the line
Code:
oCell.Shading.BackgroundPatternColor = wdColorWhite
add the line
Code:
oCell.Range.Font.Shading.BackgroundPatternColor = wdColorAutomatic
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 08-08-2019, 06:02 AM
Colin Vicary Colin Vicary is offline Text Background Colour in a Table Windows 10 Text Background Colour in a Table Office 2016
Novice
Text Background Colour in a Table
 
Join Date: Aug 2019
Posts: 3
Colin Vicary is on a distinguished road
Default

Perfect!

Thanks once again for your help Graham.

Colin
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word background colour ignores Windows setting wiganken Word 1 07-19-2018 09:25 AM
Text Background Colour in a Table Changing background colour based on dropdown choice PLeo Word VBA 2 08-03-2017 07:40 AM
Text Background Colour in a Table VBA Table – Search All Tables - Find & Replace Text in Table Cell With Specific Background Color jc491 Word VBA 8 09-30-2015 06:10 AM
Word VBA Find Table Text Shading Colour and replace with another QA_Compliance_Advisor Word VBA 10 09-19-2014 08:36 AM
Trying to clear the background colour from a theme ezekiel181 Word 1 11-14-2010 07:29 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:43 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft