Consulting

Results 1 to 15 of 15

Thread: Solved: Can we use the Color window in code?

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

    Solved: Can we use the Color window in code?

    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?
    Office 2010, Windows 7
    goal: to learn the most efficient way

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi Tom

    Before 2007 you can call the format object dialogue (ie the one behind the more colors) with
    [VBA]Call CommandBars.FindControl(Id:2624).Execute[/VBA]
    Note if a shape isn't selected it will fail.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    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!
    Office 2010, Windows 7
    goal: to learn the most efficient way

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    John --

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

    [vba]
    Call CommandBars.FindControl(Id:=2624).Execute ' need the = sign
    [/vba]


    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

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    1005 = the Standard Tab on the color window. That will work for my needs for now.

    Thanks a lot!
    Office 2010, Windows 7
    goal: to learn the most efficient way

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    John, that .FindControl was a great idea -- thanks

    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

    [VBA]
    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
    [/VBA]

  8. #8
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hmmm...

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

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location


    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

    Paul

  10. #10
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    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:
    [vba]
    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
    [/vba]
    Last edited by TrippyTom; 04-08-2008 at 04:38 PM.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  11. #11
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    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?

    [vba]
    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
    [/vba]
    Office 2010, Windows 7
    goal: to learn the most efficient way

  12. #12
    VBAX Newbie
    Joined
    Apr 2008
    Posts
    1
    Location

    Re: Color selection window

    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.

  13. #13
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Tom,
    I was able to get the color wheel to work like this:
    [VBA]
    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

    [/VBA]

    I will now try to just get the color selected.

    This is some great help you have here

  14. #14
    VBAX Expert TrippyTom's Avatar
    Joined
    Jul 2005
    Location
    New York, NY (USA)
    Posts
    556
    Location
    So they key is the DoEvents? I didn't know about this particular function.

    That's handy to know about! Thanks again Tommy.
    Office 2010, Windows 7
    goal: to learn the most efficient way

  15. #15
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    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

Posting Permissions

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