Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-12-2014, 08:09 AM
ScotsMaverick ScotsMaverick is offline Colour code mail merge header table cell backgrounds Windows 7 64bit Colour code mail merge header table cell backgrounds Office 2010 32bit
Novice
Colour code mail merge header table cell backgrounds
 
Join Date: Jun 2014
Posts: 2
ScotsMaverick is on a distinguished road
Default Colour code mail merge header table cell backgrounds

Hi,



So here's the problem that's been challenging me the last few hours. I've recently been creating a mail merged document which I had hoped to have generating different coloured headers for each mail merged page depending on a mail merged field in the header table called "Category".

The goal is to change this cell's background colour on every page depending on the text that has been mail merged into the cell. I've previously done a bit of amateur VBA using excel, but the difficulties of selecting post-mail merged header cells using bookmarks in word are defeating me.

It's rough but here is the code skeleton

Code:
Sub ColourCode()

Dim Cat1 As String
Dim Cat2 As String
Dim Cat3 As String
Dim Cat4 As String
Dim Cat5 As String
Dim X As Integer
Dim Ctext As String

Cat1 = "Category: 1 - Easy fix"
Cat2 = "Category: 2 - Instrument tubing fix"
Cat3 = "Category: 3 - Further assessment"
Cat4 = "Category: 4 - Clamp"
Cat5 = "Category: 5 - Engineering"

Documents.Open FileName:="C:\Users\me\Documents\Letters1.docm"

X = ActiveDocument.Pages.Count

For Each ActiveDocument.Tables In ActiveDocument

If ActiveDocument.Bookmarks("Category").Range.Text = Cat1 Then
    Bookmarks("Category").Range.Shading.BackgroundPatternColorIndex = wdBlue
ElseIf ActiveDocument.Bookmarks("Category").Range.Text = Cat2 Then
    Bookmarks("Category").Range.Shading.BackgroundPatternColorIndex = wdGreen
ElseIf ActiveDocument.Bookmarks("Category").Range.Text = Cat3 Then
    Bookmarks("Category").Range.Shading.BackgroundPatternColorIndex = wdRed
ElseIf ActiveDocument.Bookmarks("Category").Range.Text = Cat4 Then
    Bookmarks("Category").Range.Shading.BackgroundPatternColorIndex = wdYellow
ElseIf ActiveDocument.Bookmarks("Category").Range.Text = Cat5 Then
    Bookmarks("Category").Range.Shading.BackgroundPatternColorIndex = wdPink
End If

Next

End Sub
Cheers to anyone that can help
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to immediately change the colour of a cell depending on the code placed in anothe Phil Payne Excel Programming 2 07-27-2013 11:04 PM
Mail Merge Code (Default Display) ochiha_ita Mail Merge 3 04-22-2013 04:04 AM
Colour code mail merge header table cell backgrounds Mail merge in a header Kizzy Mail Merge 1 08-13-2012 10:50 AM
Mail merge Field Code Manipulation macjnr Mail Merge 0 09-10-2009 11:37 AM
Colour code mail merge header table cell backgrounds Code for Changing Cell Backgrounds leroytrolley Excel 2 12-05-2008 02:05 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:30 PM.


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