![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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 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 |
|
#5
|
|||
|
|||
|
Perfect!
Thanks once again for your help Graham. Colin |
|
| 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 |
Changing background colour based on dropdown choice
|
PLeo | Word VBA | 2 | 08-03-2017 07:40 AM |
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 |