#1
|
||||
|
||||
Help with macro to set font colors
Could some kind soul help me with at least the outline of a macro to scan a table containing RGB settings and apply those settings to the text and fill of adjacent columns? My table has these 6 columns: R G B Fill Text Comments. The first row is a header with that text. The subsequent rows contain RGB settings (0-255) in the first three columns, nothing in the Fill column, and text in the last 2 columns. I would like a macro that would scan the table, extract the RGB settings from the first three columns, then set the fill in column 4 and the text in columns 5 & 6 to those settings. Here's a sample table: Code:
R G B Fill Text Comments 0 0 255 Sample text Pure blue 0 255 0 Sample text Pure green 255 0 0 Sample text Pure red 255 255 0 Sample text Pure yellow 94 38 18 Sample text Sepia 230 230 250 Sample text Lavender 178 34 34 Sample text Firebrink |
#2
|
||||
|
||||
Hi Jenn,
Try something based on: Code:
Sub ColorIt() Dim i As Long, R As Long, G As Long, B As Long, Rng As Range With ActiveDocument.Tables(1) For i = 2 To .Rows.Count Set Rng = .Cell(i, 1).Range Rng.End = Rng.End - 1 R = CLng(Rng.Text) Set Rng = .Cell(i, 2).Range Rng.End = Rng.End - 1 G = CLng(Rng.Text) Set Rng = .Cell(i, 3).Range Rng.End = Rng.End - 1 B = CLng(Rng.Text) .Cell(i, 4).Shading.BackgroundPatternColor = RGB(R, G, B) .Cell(i, 5).Shading.BackgroundPatternColor = RGB(R, G, B) Next i End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
MAcro to List all the Font & its size in a word document | shaukat74 | Word VBA | 1 | 01-29-2013 09:34 PM |
Change single character in PPT to another font macro | rtwwpad | PowerPoint | 1 | 01-19-2013 05:08 PM |
Unable to change font colors from theme colors | choy | Word | 3 | 08-01-2012 09:12 PM |
How can I match font colors? | nestorph | Office | 2 | 10-28-2011 03:11 PM |
Font colors | JerryB | Excel | 1 | 11-30-2008 10:23 AM |