Hi Nick,
I don't know a way to get the colour directly either. As you say with
customized colours the tooltip may be incorrect.
I've never managed to get SendMessage to work with toolbars. Another way
that should be possible is to get the colour of the pixel of the coloured
bar in the Fill icon.
Determine the toolbar that has the Fill Color icon/toolbar, typically
"Formatting"
Get the screen pixel position of the icon relative to top/left of the
container tlbr, then offset to a pixel in the 'coloured bar' in the icon,x/y
Get hwnd then the dc of the toolbar
GetPixel dc, x,y
ReleaseDC
Simple <g
Regards,
Peter T
"NickHK" wrote in message
...
I just had a quick look and yes, it does not seem to be straight forward.
This control is of type msoControlSplitButtonPopup (= 13) and does not
support events, apparently. And calling .Execute causes the drop down,
rather than filling the .Selection.
I see no correlation between the ToolTipText and the colour shown, as it
can
be completely wrong if colours are modified to custom colours, in XL2002
anyway.
e.g. I modified "Light Green" to a pinkish and the ToolTipText still shows
"Light Green" instead of maybe "Custom" or an RGB.
A quick look with Spy++ shows these messages when clicking the control to
fill the selected cell(s) with the visible colour:
<00425 00010554 P WM_LBUTTONDOWN fwKeys:MK_LBUTTON xPos:577 yPos:13
<00426 00010554 S
.................................................. ...........................
.............WM_NCHITTEST xPos:582 yPos:87
<00427 00010554 R
.................................................. ...........................
.............WM_NCHITTEST nHittest:HTCLIENT
<00428 00010554 S
.................................................. ...........................
.............WM_WINDOWPOSCHANGING lpwp:0012FA70
<00429 00010554 R
.................................................. ...........................
.............WM_WINDOWPOSCHANGING
<00430 00010554 S
.................................................. ...........................
.............WM_CAPTURECHANGED hwndNewCaptu00010554
<00431 00010554 R
.................................................. ...........................
.............WM_CAPTURECHANGED
<00432 00010554 P WM_SETCURSOR hwnd:00010554 nHittest:HTNOWHERE
wMouseMsg:0000
<00433 00010554 P WM_LBUTTONUP fwKeys:0000 xPos:577 yPos:13
So unless anyone has a better idea:
- Determine which of the above messages (if they are indeed correct) are
actually needed.
- Get the hwnd of the Formatting commandbar; FindWindow/FindWindowEx etc.
- SendMessage, using hwnd and the appropriate parameters.
Seems like a lot of work, so I would hope this is important to you <g.
NickHK
"Bob Phillips" wrote in message
...
No, this is very difficult. We had a discussion on OzGrid a while back
(http://www.ozgrid.com/forum/showthread.php?t=41954) but it was hardly
satisfactory.
--
HTH
Bob
(there's no email, no snail mail, but somewhere should be gmail in my
addy)
"JasonF" wrote in message
ups.com...
Is there a way to determine what the current / last used color index
number is from VBA? Instead of hard coding the colorindex or forcing
the user to choose a color, I would like to just pick up the color
that's currently in the toolbar? I've found the name:
Application.CommandBars("Formatting").Controls("Fi ll
Color").TooltipText
However, I'd like to get the ColorIndex number for the name. Any
ideas?