Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2013, 08:56 AM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Help with macro to set font colors Windows XP Help with macro to set font colors Office 2007
Competent Performer
Help with macro to set font colors
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default 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
The macro would set the fill color in the Fill column and the and text color in the last 2 columns to the corresponding RGB colors.
Reply With Quote
  #2  
Old 09-29-2013, 09:57 PM
macropod's Avatar
macropod macropod is offline Help with macro to set font colors Windows 7 32bit Help with macro to set font colors Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
PS: Sepia is actually 112, 66, 20
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with macro to set font colors 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
Help with macro to set font colors Unable to change font colors from theme colors choy Word 3 08-01-2012 09:12 PM
Help with macro to set font colors How can I match font colors? nestorph Office 2 10-28-2011 03:11 PM
Help with macro to set font colors Font colors JerryB Excel 1 11-30-2008 10:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:31 PM.


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