Consulting

Results 1 to 4 of 4

Thread: Solved: Trigger background color change on shape?

  1. #1
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location

    Solved: Trigger background color change on shape?

    Is there a way to trigger a macro when a shape's background color is set? The reason I was wondering is I'd like to automatically:
    - change the text to black if it's a light background, or ...
    - change the text to white if it's a dark background
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    By the way, I was hoping to utilize this formula to determine the White/Black values:
    http://www.codeproject.com/cs/media/IdealTextColor.asp

    I just need to know if I can use the macro as some sort of trigger, or if I should do it on all shapes on the current slide, or something.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    Well, I decided to go at this from a different perspective. Since we use very specific colors at work (a template), I decided to just change it to a subset of only those colors, so I know if the text should go white or black automatically.

    If anyone knows of a way to trigger this whenever a fill color is changed, I'd still like to know just for learning purposes.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    How would I turn this into a CASE statement?

    [vba]
    With ActivePresentation.Slides(mySlide).Shapes
    If .Range.HasTextFrame Then
    If .Range.Fill.ForeColor.RGB = RGB(255, 255, 255) Then
    .Range.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
    End If
    [/vba]

    ... NEVERMIND
    I figured it out.
    [VBA]
    For Each shp In ActivePresentation.Slides(mySlide).Shapes
    If shp.HasTextFrame Then
    Select Case shp.Fill.ForeColor.RGB
    Case Is = RGB(255, 255, 255) 'white
    shp.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
    [/VBA]
    Last edited by TrippyTom; 03-02-2007 at 01:00 PM.
    Office 2010, Windows 7
    goal: to learn the most efficient way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •