Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2014, 06:04 AM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default Multiple macros on same shortcut

Hi.



Would like to change background color, and font color with a macro. But I want them all to be in a order on the same shortcut.
For each time I press the shortcut, It will change the color. Is there a way to do that?

Color combinations I want on "F9":
| B:White F:Black | B: Black F:White | B:Black F:Yellow |

I also got a problem when recording. I record changing the font color from white to red/yellow/blue/green etc. When I run the macro, it will change the color from white to black when. What is wrong?
Reply With Quote
  #2  
Old 06-12-2014, 05:14 PM
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: 21,963
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

What you're asking for isn't feasible, since there's no way for the macro to store the details of the last change. Setting up some logic to change white to black, black to yellow and yellow to white, in sequence, is easy enough. But not going from white to black, black to either yellow or white. Indeed, it's not at all clear what the criteria are for the final black to yellow to be triggered as an alternative to the black to white.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-12-2014, 11:03 PM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

It don't need to remember my last choice, as long as I could use the same button to swith between them.

1 push: Black on white.
2 pushes: White on black.
3 pushes: Yellow on black.

If i push to times quickly, I will get white on black. If I press 3 times, it will be Yellow on black. If I got White on black, and want black on white, It's okey to press one time.

Is this possible?
Reply With Quote
  #4  
Old 06-13-2014, 12:05 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: 21,963
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

Try:
Code:
Sub Colorize()
With Selection.Range
  Select Case .Font.ColorIndex
    Case wdAuto, wdBlack
      .Font.ColorIndex = wdWhite
      .HighlightColorIndex = wdBlack
    Case wdWhite
      .Font.ColorIndex = wdYellow
      .HighlightColorIndex = wdBlack
    Case wdYellow
      .Font.ColorIndex = wdAuto
      .HighlightColorIndex = wdNoHighlight
  End Select
End With
End Sub
For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-13-2014, 02:07 AM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

Thanks Macropod! That worked just fine.

when I said background color, I ment the whole paper, not just the line behind the text, and is it possible for the macro to mark the whole text and change like (CTRL+A), and then re-mark the text, so I don't delete it all when I start to write

:-)

Again, thank you so much
Reply With Quote
  #6  
Old 06-13-2014, 03:06 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: 21,963
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

Simply change 'Selection' to 'ActiveDocument'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 06-13-2014, 03:28 AM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

Thanks again :-)

If I understand the macro right, I would like to change the "HighlightColorIndex" into something like "Background(...)", so the background would change color, and not the Highlight-color.

You have a formula for that one?
Reply With Quote
  #8  
Old 06-13-2014, 03:50 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: 21,963
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

You could try changing '.HighlightColorIndex' to '.Shading.BackgroundPatternColorIndex'. I'm not sure how well that will work with coloured fonts, though.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 06-13-2014, 06:18 AM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

Thanks again. Really appreciate your help

That one made a black box around the text. I think it's easier to use two macros. One for font color, and one for page/background color. Manually I can change the background color. My Office is not in english, so I don't know the english button label, but maybe something like "page color / fill color". This button changes the color for the whole page, as if i could print a yellow page.

Is there a macro for changing between Yellow, White and Black fill color on same short key, just like the font color?
Reply With Quote
  #10  
Old 06-13-2014, 04:05 PM
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: 21,963
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

It wasn't apparent from what you had previously posted that you wanted the entire page to change colour, and not just the text. For that, you could use:
Code:
Sub Colorize()
With ActiveDocument
  .Background.Fill.Visible = msoTrue
  Select Case .Range.Font.ColorIndex
    Case wdAuto, wdBlack
      .Range.Font.ColorIndex = wdWhite
      .Background.Fill.BackColor.TintAndShade = wdBlack
    Case wdWhite
      .Range.Font.ColorIndex = wdYellow
      .Background.Fill.BackColor.TintAndShade = wdBlack
    Case wdYellow
      .Range.Font.ColorIndex = wdAuto
      .Background.Fill.BackColor.TintAndShade = wdNoHighlight
      .Background.Fill.Visible = msoFalse
  End Select
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 06-16-2014, 06:50 AM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

This was really not easy. Programming in VBA is clearly not my strength. I tried to use your latest code, but it don't seem to be stable. After 10-20 executions, it stops working. Now I have made four macros, which I want into one "Select Case" (?). If you could do that for me, I would really much appreciate that! Have used 4 hour at work with this, but are about to give up.

Code:
Sub HvitBlatt()
ActiveDocument.Range.Font.ColorIndex = wdWhite
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(0, 0, 255)
ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub '
 
'
'
'
Sub SvartGul()
ActiveDocument.Range.Font.ColorIndex = wdBlack
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 0)
ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub '
 
'
'
'
Sub HvitSvart()
ActiveDocument.Range.Font.ColorIndex = wdBlack
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(255, 255, 255)
ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub '
 
'
'
'
Sub SvartHvitt()
ActiveDocument.Range.Font.ColorIndex = wdWhite
ActiveDocument.Background.Fill.ForeColor.RGB = RGB(0, 0, 0)
ActiveDocument.Background.Fill.ForeColor.TintAndShade = 0
ActiveDocument.Background.Fill.Visible = msoTrue
ActiveDocument.Background.Fill.Solid
End Sub '
Reply With Quote
  #12  
Old 06-16-2014, 08:04 PM
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: 21,963
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

Your four macros are equivalent to:
Code:
Sub Colorize()
With ActiveDocument
  With .Background.Fill
    .ForeColor.TintAndShade = 0
    .Visible = msoTrue
    .Solid
  End With
  Select Case .Range.Font.ColorIndex
    Case wdWhite
      Select Case .Background.Fill.ForeColor.RGB
        Case RGB(0, 0, 255)  'Blue
          .Background.Fill.ForeColor.RGB = RGB(0, 0, 0) 'Black
        Case RGB(0, 0, 0)  'Black
          .Range.Font.ColorIndex = wdAuto
          .Background.Fill.ForeColor.RGB = RGB(255, 255, 255) 'White
      End Select
    Case wdAuto, wdBlack
      Select Case .Background.Fill.ForeColor.RGB
        Case RGB(255, 255, 255) 'White
          .Background.Fill.ForeColor.RGB = RGB(255, 255, 0) 'Yellow
        Case RGB(255, 255, 0) 'Yellow
          .Range.Font.ColorIndex = wdWhite
          .Background.Fill.ForeColor.RGB = RGB(0, 0, 255) 'Blue
        End Select
  End Select
End With
End Sub
It seems, though, that you only want two font colours, not three, and four different backgrounds, not three.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 06-29-2014, 11:56 PM
orjanmen orjanmen is offline Multiple macros on same shortcut Windows 8 Multiple macros on same shortcut Office 2010 64bit
Novice
Multiple macros on same shortcut
 
Join Date: Jun 2014
Posts: 7
orjanmen is on a distinguished road
Default

Thanks! This is the code I ended up with. There is one issue thou! Some times it will not execute if the documents start with yellow background fill. And some times it will not execute if the document starts with black background fill.

Is there a reason for that? There is no problem to start with a black background, but it don's seem consequent.

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) 'SvartBakgrunn
        Case RGB(0, 0, 0) 'Svart
            .Range.Font.ColorIndex = wdAuto
            .Background.Fill.ForeColor.RGB = RGB(255, 255, 255) 'HvitBakgrunn
        End Select
    Case wdAuto, wdBlack 'SvartSkrift
        Select Case .Background.Fill.ForeColor.RGB
        Case RGB(255, 255, 255) 'HvitBakgrunn
            .Background.Fill.ForeColor.RGB = RGB(255, 255, 0) 'GulBakgrunn
        Case RGB(255, 255, 0)
            .Range.Font.ColorIndex = wdWhite
            .Background.Fill.ForeColor.RGB = RGB(0, 0, 255) 'BlåBakgrunn
        End Select
    End Select
End With
End Sub

Last edited by macropod; 06-30-2014 at 12:02 AM. Reason: Added code formatting
Reply With Quote
  #14  
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: 21,963
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 01:05 AM.


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