Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2014, 12:36 AM
macropod's Avatar
macropod macropod is offline Multiple macros on same shortcut Windows 7 32bit Multiple macros on same shortcut Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple macros on same shortcut shortcut key to namebox? gsrikanth Excel 8 11-05-2022 04:10 AM
Multiple macros on same shortcut Document as shortcut? sparkync Office 3 08-04-2012 03:26 PM
Multiple macros on same shortcut office xp shortcut 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:48 AM.


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