![]() |
|
#1
|
||||
|
||||
![]()
The way the code works, it looks first at the font colour, to see whether it's white or black. If it's not either of those colours, it does nothing.
If the font is white, the code looks at the background colour, to see whether it's blue or black. If it's not either of those colours, it does nothing. If the font is 'auto' (black), the code looks at the background colour, to see whether it's white or yellow. If it's not either of those colours, it does nothing. So, if you start off with a document that has red text, the macro does nothing. It also does nothing if the document has white text and a yellow background or black text and a pink background, for example. One of the problems with checking against RGB colours is that what might look white, for example, might have RGB(255, 255, 254) or RGB(255, 254, 255) or RGB(254, 255, 255) or RGB(254, 254, 254), amongst others, instead of RGB(255, 255, 255). So you might want a 'Case Else' result for both the font colour and the background. For example: Code:
Sub BytteFargekombinasjon() With ActiveDocument With .Background.Fill .ForeColor.TintAndShade = 0 .Visible = msoTrue .Solid End With Select Case .Range.Font.ColorIndex Case wdWhite 'HvitSkrift Select Case .Background.Fill.ForeColor.RGB Case RGB(0, 0, 255) 'BlåBakgrunn .Background.Fill.ForeColor.RGB = RGB(0, 0, 0) 'Svart Case Else .Range.Font.ColorIndex = wdAuto .Background.Fill.ForeColor.RGB = RGB(255, 255, 255) 'HvitSkrift End Select Case wdAuto, wdBlack Select Case .Background.Fill.ForeColor.RGB Case RGB(255, 255, 255) 'HvitSkrift .Background.Fill.ForeColor.RGB = RGB(255, 255, 0) 'GulBakgrunn Case Else .Range.Font.ColorIndex = wdWhite 'HvitSkrift .Background.Fill.ForeColor.RGB = RGB(0, 0, 255) 'BlåBakgrunn End Select Case Else .Range.Font.ColorIndex = wdAuto .Background.Fill.ForeColor.RGB = RGB(255, 255, 255) 'HvitSkrift End Select End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
gsrikanth | Excel | 8 | 11-05-2022 04:10 AM |
![]() |
sparkync | Office | 3 | 08-04-2012 03:26 PM |
![]() |
nja | Word VBA | 1 | 10-24-2009 05:07 AM |
Where is the MS Office Shortcut Bar? | vwm12345 | Office | 0 | 11-14-2008 04:30 AM |
Style shortcut | billzant | Word | 0 | 01-06-2007 02:13 AM |