PDA

View Full Version : Solved: Can we use the Color window in code?



TrippyTom
12-13-2007, 10:40 AM
Is it possible to bring up the Color window that appears when you click an object to assign a color? (see image) I would like to use this to get user-selected color and assign it to a variable.

I guess as a broader question, is there a website or reference somewhere that shows how I can access all windows in PowerPoint?

John Wilson
12-14-2007, 04:53 AM
Hi Tom

Before 2007 you can call the format object dialogue (ie the one behind the more colors) with
Call CommandBars.FindControl(Id:2624).Execute
Note if a shape isn't selected it will fail.

TrippyTom
12-14-2007, 07:22 AM
aha! So what I should do, is add a shape to the slide, then call the window, then pickup whatever color the shape is after the user makes their choice, right? (and delete the shape after I put that choice to a variable)

This is great :) Thanks!

Paul_Hossler
12-14-2007, 10:39 AM
John --

1. I think it should be (need the equal sign) (nit)



Call CommandBars.FindControl(Id:=2624).Execute ' need the = sign



2. Any way of going to the color wheel directly? (nit)

3. Most importantly, where can I find the ID mappings for other controls. This looks like a great way to "fake out" PP because it doesn't expose it's Dialogs collection to VBA the way Work and Excel do.

Thanks

Paul

John Wilson
12-14-2007, 12:19 PM
Your right I missed an = Doh!

I have a pretty extensive list if you (Tom or Paul) would like to email me with things that interest you. I wasn't able to get to the colors sub menu though and it won't work in 2007!
john AT technologytrish.co.uk

TrippyTom
12-14-2007, 02:24 PM
1005 = the Standard Tab on the color window. That will work for my needs for now.

Thanks a lot!

Paul_Hossler
12-14-2007, 07:15 PM
John, that .FindControl was a great idea -- thanks :bow: :beerchug: :thumb :cloud9:

Never knew about it. Threw together (right word) some VBA to loop through the IDs and write the captions to a text file, and experimented with some of the IDs. It's not very user friendly compared to Word or Excel's .Dialogs collection, but browsing through the list it does offer some interesting possibilities.

Thanks again

Paul


Sub Build_ID_List()
Dim i As Long
Dim c As CommandBarControl

Open "c:\ID.txt" For Output As #1
For i = 1 To 32000
Set c = Nothing
On Error Resume Next
Set c = CommandBars.FindControl(, i)

If Not c Is Nothing Then Print #1, i, c.Caption
NextI:
Next i

Close #1

MsgBox "Done"
End Sub

'many have no apparent effect unless the right object is selected
'NO real checking - should test that the Selection is 'compatible'
Sub Test_Control_ID()
Const cID As Long = 1005
Dim ctrl As CommandBarControl
Set ctrl = Nothing

On Error Resume Next
Set ctrl = CommandBars.FindControl(, cID)
On Error GoTo 0

If Not ctrl Is Nothing Then
On Error Resume Next
ctrl.Execute
On Error GoTo 0
End If
End Sub

TonyJollans
12-19-2007, 10:01 AM
Hmmm...

You think Word's Dialog Collection is user-friendly? <g>

Paul_Hossler
12-20-2007, 06:23 AM
:rotlaugh:

Never understood (except it's Micro$oft) why PP didn't expose more of it's objects to VBA.

Also, why the "macro recorder" doesn't :dunno :banghead:

Paul

TrippyTom
04-08-2008, 03:43 PM
Hi guys,
I hope someone sees this question because it has been a while since I first posted this.

Anyway, I can't figure out how to associate the calling of this window with the shape I'm adding to the page.
What I want to do is:
1) add shape to current slide
2) call color window via .... Call CommandBars.FindControl(Id:=1051).Execute <-- this is the color window I want
3) How do I pickup the user's choice and assign it to a Public RGB value (GuideVal)
4) Delete shape

Here's my code so far:

Public GuideVal As RGBColor

Sub testColorWindow()
Dim shp As Shape
Dim mySlide As Long
mySlide = ActiveWindow.View.Slide.SlideIndex
Set shp = ActivePresentation.Slides(mySlide).Shapes.AddShape(Type:=msoShapeRectangle, Left:=0, Top:=0, Width:=50, Height:=50)
With shp
.Fill.Visible = msoTrue
.Fill.Solid
'.Fill.ForeColor.RGB = GuideVal '<---- How do I open the color window before setting the color here?
.Fill.Transparency = 0#
End With
End Sub

TrippyTom
04-09-2008, 08:47 AM
Ok, it turns out I need to have the object actually selected for it to work. Now my code does change the fill color, but the msgbox shows up BEFORE I get the color window. How do I get the actual color the user chooses?


Sub testColorWindow()
Dim shp As Shape
Dim mySlide As Long
Dim myObject As Variant
Dim GuideVal2 As Variant
mySlide = ActiveWindow.View.Slide.SlideIndex
Set shp = ActivePresentation.Slides(mySlide).Shapes.AddShape(Type:=msoShapeRectangle, Left:=1, Top:=1, Width:=50, Height:=50)
With shp
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.Transparency = 0#
.Line.Visible = msoFalse
End With
shp.Select
With ActiveWindow.Selection
Call CommandBars.FindControl(Id:=1051).Execute
Set GuideVal2 = .ShapeRange.Fill.ForeColor
MsgBox ("Color is " & GuideVal2)
End With
End Sub

Timswa
04-12-2008, 10:50 AM
Hm, I was not smart enough to find that color picking window. So I made my own. I think it's better :P. If you want the code, you can PM me.
It looks like this: (Sorry, but the terms are in Dutch; I presume it is readable anyway)

ht tp://img258.imageshack.us/img258/6680/kleurenkiezerki3.png (remove the space)

PS: I picked the coloured image from the internet, I did not know a way to set the color value for each pixel in an image.

Tommy
04-13-2008, 07:34 AM
Hi Tom,
I was able to get the color wheel to work like this:

Sub testColorWindow()
Dim Shp As Shape
Dim shp2 As Shape
'added this to hopefully get some control
Dim Helper As CommandBarControl
'
Dim mySlide As Long
Dim myObject As Variant
Dim GuideVal As Variant
Dim oRed As Integer
Dim oGreen As Integer
Dim oBlue As Integer

mySlide = ActiveWindow.View.Slide.SlideIndex
Set Shp = ActivePresentation.Slides(mySlide).Shapes.AddShape(Type:=msoShapeRectangle, Left:=1, Top:=1, Width:=50, Height:=50)
With Shp
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.Transparency = 0#
.Line.Visible = msoFalse
.Select
'changed this
Set Helper = CommandBars.FindControl(Id:=1051) '.Execute
'added these 2 lines
Helper.Execute
'this is to give the program time to do what it has to do
DoEvents
'tada done
Set GuideVal = Shp.Fill.ForeColor

oRed = GuideVal And &HFF&
oGreen = (GuideVal And &HFF00&) / 256
oBlue = (GuideVal And &HFF0000) / 65536
Set Helper = Nothing
MsgBox ("red = " & oRed & vbCr & "green = " & oGreen & vbCr & "blue = " & oBlue)
End With
End Sub



I will now try to just get the color selected.

This is some great help you have here :)

TrippyTom
04-14-2008, 08:45 AM
So they key is the DoEvents? I didn't know about this particular function. :)

That's handy to know about! Thanks again Tommy.

Tommy
04-14-2008, 05:55 PM
The Doevents is just half the key, I set a local variable to the control so I could have some control over it and the program would wait until I made a selection before the code continued. The DoEvents was to give the control time to populate the "selected" shape with the infomation that I was looking for.

No it will not let yo get it all at once, you have to work for, it tickle it a little, and maybe, just maybe, you get what you want LOL :devil2: