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
You'll notice now that instead of checking whether the font is just 'auto' (black) or white, it has a third check for any other colour. And, instead of looking for blue/black and white/yellow backgrounds, in now just checks for blue/non-blue and white/non-white. That means that, regardless of the starting combination, you'll be able to get any of your preferred combinations in no more than two cycles.