Solved

I need a color picker for use with Word VBA (2000 and up on Windows 2000 and XP).

Posted on 2006-07-23
16
920 Views
Last Modified: 2012-05-05
Hi all,

I need a color picker for use with Word VBA (2000 and up on Windows 2000 and XP). Like the WIndows/Office Colors dialog box.

It must let you choose a color and return the 24-bit value.

thanks,

avi
0
Comment
Question by:progtw
  • 7
  • 7
  • 2
16 Comments
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 17163242
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 17163243
Ah, sorry, you wanted to do this within VBA.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17163278
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:progtw
ID: 17164187
to rockiroads:

I think you have given me a link to utilities which allow me to pick a color from whatever *happens* to be in screen.  

I meant something else. What I meant was a color selector of the type that you see a lot in Windows and Office. There is a dialog box called Colors which allows you to select any color of the rainbow, or make your own by giving RGB values while seeing whast they look like in the sample window. And there are two tabs. One contains a preset pallette of "honeycomb" colored hex shapes. And the other tab gives you the full range of all colors and hues etc. We use thme to set font colors or fill colors. I am sure that this dialog box must be available vrom in Windows, but I don't know how to access it. I want to access such a function using VBA to return me the user's color selection.

tia

avi
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17164314
The links are to Active X controls in which you can make use of in code.

I know what you mean, the only way possibly is if you include the common api dialog


0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 17164341
ok, thought occurred ,use of API's
so lets try the common dialog api as suggested

u could add it as a reference then use it as a datatype

or this this bit of code

'Add this lot in a macro

Private Type CHOOSECOLORSTRUCT
   lStructSize     As Long
   hwndOwner       As Long
   hInstance       As Long
   rgbResult       As Long
   lpCustColors    As Long
   flags           As Long
   lCustData       As Long
   lpfnHook        As Long
   lpTemplateName  As String
End Type

Private Declare Function ChooseColor Lib "comdlg32.dll" _
   Alias "ChooseColorA" _
  (lpcc As CHOOSECOLORSTRUCT) As Long


'Here is functon that opens dialog and displays result
Public Sub PickColor()


    Dim cc As CHOOSECOLORSTRUCT
    Dim dwCustClrs(0 To 15) As Long

   
    With cc
        .flags = &H100
        .flags = .flags Or &H1
        .lStructSize = Len(cc)
        .hwndOwner = 0
        .lpCustColors = VarPtr(dwCustClrs(0))
    End With
   
    If ChooseColor(cc) = 1 Then
        MsgBox "Colour Selected : " & cc.rgbResult
    End If
End Sub


0
 

Author Comment

by:progtw
ID: 17168798
So far so good it seems to work.

Am I supposed to be able to see an entry for comdlg32 in the VBA Object Browser?

avi
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17170515
I dont know if u have to add it as a reference.
But since the code I posted makes use of it as a API function instead, there is no reason to worry about references
0
 

Author Comment

by:progtw
ID: 17190489
Sorry about the delay.
You mean the function is a Windows "kernel" API function? (I don't know if the word "kernel" is the right way of saying this.)

avi
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17190968
Well kernel is more system. Windows is just full of lots of dll's. This code just making use of one of them. I believe this dll is shipped with windows as it contains common dialogs used by windows
0
 

Author Comment

by:progtw
ID: 17191085
'scuse me for picking your brains some more (well you are getting 500 points...), but pray explain to me, why do some things have to be "referenced" (ie add a reference to them) and other things, like functions in the Windows DLLs as you mention, do not require a reference to them?

Oh, and where can see a list of the functions in comdlg32.dll?

tia

avi
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17191353
I'll try to explain, I know why, I just aint that great in explaining
If you add a reference to a library, it means your code can access all the methods available in that dll
You cannot use something in that dll unless u reference it somehow


Where can a list of funcs be found in comdlg32? I dont know, I only have used it for a few things
0
 

Author Comment

by:progtw
ID: 17191427
thnx

>> You cannot use something in that dll unless u reference it somehow
But earlier you wrote, and I quote, "But since the code I posted makes use of it as a API function instead, there is no reason to worry about references".
?

tia

avi
0
 

Author Comment

by:progtw
ID: 17191519
Ok, now I think I understand. The API function declaration code you wrote (quoted below) is the reference:

Private Declare Function ChooseColor Lib "comdlg32.dll" _
   Alias "ChooseColorA" _
  (lpcc As CHOOSECOLORSTRUCT) As Long

?

avi
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17191539
Yes, I am sepcifically defining what function to use in that DLL

Sorry about the confusion with references earlier. I meant actually adding a reference (Tools/References) as opposed to specifying a DLL function to use via code
0
 

Author Comment

by:progtw
ID: 17191628
Thanks,

I finally got around to testing it out by pickin a color and using it to shade a selection in a doc. Works. Great!

avi
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
This article was originally published on Monitis Blog, you can check it  here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sour…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question