View Single Post
  #2   Report Post  
P Daulton
 
Posts: n/a
Default

No one having answered this so far I thought I'd have a go..
I couldn't find anything in the object model to look at for this, but that's
because I don't have an extensive excel object model to look at.
I did however find that
CommandBars("Formatting").Controls(24)
was the fill colour button showing on the menu bar, but the only property
that I could find which changed was its ToolTipText, the text that shows up
after hovering over the button. This text remains the same even if the
palette colours are changed!
So the following macro looks at that text, converts it into the index value,
converts it into rgb and uses that to colour the fill of the first shape
object on the first worksheet. It's done in steps below, it could be
condensed.
I think Steve's right, there MUST be a better way.
Pascal
ps one small snag, if the user alters the palette later, the filled shapes
won't change whereas cell fills will.



Sub ToolTipTextColour()
Select Case CommandBars("Formatting").Controls(24).TooltipText
Case "Fill Color (Automatic)"
mycolorindex = xlNone
Case "Fill Color (Black)"
mycolorindex = 1
Case "Fill Color (Brown)"
mycolorindex = 53
Case "Fill Color (Olive Green)"
mycolorindex = 52
Case "Fill Color (Dark Green)"
mycolorindex = 51
Case "Fill Color (Dark Teal)"
mycolorindex = 49
Case "Fill Color (Dark Blue)"
mycolorindex = 11
Case "Fill Color (Indigo)"
mycolorindex = 55
Case "Fill Color (Gray-80%)"
mycolorindex = 56
Case "Fill Color (Dark Red)"
mycolorindex = 9
Case "Fill Color (Orange)"
mycolorindex = 46
Case "Fill Color (Dark Yellow)"
mycolorindex = 12
Case "Fill Color (Green)"
mycolorindex = 10
Case "Fill Color (Teal)"
mycolorindex = 14
Case "Fill Color (Blue)"
mycolorindex = 5
Case "Fill Color (Blue-Gray)"
mycolorindex = 47
Case "Fill Color (Gray-50%)"
mycolorindex = 16
Case "Fill Color (Red)"
mycolorindex = 3
Case "Fill Color (Light Orange)"
mycolorindex = 45
Case "Fill Color (Lime)"
mycolorindex = 43
Case "Fill Color (Sea Green)"
mycolorindex = 50
Case "Fill Color (Aqua)"
mycolorindex = 42
Case "Fill Color (Light Blue)"
mycolorindex = 41
Case "Fill Color (Violet)"
mycolorindex = 13
Case "Fill Color (Gray-40%)"
mycolorindex = 48
Case "Fill Color (Pink)"
mycolorindex = 7
Case "Fill Color (Gold)"
mycolorindex = 44
Case "Fill Color (Yellow)"
mycolorindex = 6
Case "Fill Color (Bright Green)"
mycolorindex = 4
Case "Fill Color (Turquoise)"
mycolorindex = 8
Case "Fill Color (Sky Blue)"
mycolorindex = 33
Case "Fill Color (Plum)"
mycolorindex = 54
Case "Fill Color (Gray-25%)"
mycolorindex = 15
Case "Fill Color (Rose)"
mycolorindex = 38
Case "Fill Color (Tan)"
mycolorindex = 40
Case "Fill Color (Light Yellow)"
mycolorindex = 36
Case "Fill Color (Light Green)"
mycolorindex = 35
Case "Fill Color (Light Turquoise)"
mycolorindex = 34
Case "Fill Color (Pale Blue)"
mycolorindex = 37
Case "Fill Color (Lavender)"
mycolorindex = 39
Case "Fill Color (White)"
mycolorindex = 2
Case Else
mycolorindex = xlNone
End Select
If mycolorindex < xlNone Then
myrgb = ActiveWorkbook.Colors(mycolorindex)
With Worksheets(1).Shapes(1).Fill
.ForeColor.RGB = myrgb
.Visible = True
End With
Else: Worksheets(1).Shapes(1).Fill.Visible = msoFalse
End If
End Sub



"Steve Conary" wrote in message
oups.com...
I have a routine that adds a shape to a selected cell and I would like
to have the color of that shape be the last selected "fill" color (or
the default fill color if no change made since Excel was started). How
can I determine the active fill color from the "Fill Color" toolbar
using VBA? Seems like there should be a way to get that color value.
Thanks...
Steve