• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

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

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
progtw
Asked:
progtw
  • 7
  • 7
  • 2
1 Solution
 
moorhouselondonCommented:
0
 
moorhouselondonCommented:
Ah, sorry, you wanted to do this within VBA.
0
 
rockiroadsCommented:
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
progtwAuthor Commented:
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
 
rockiroadsCommented:
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
 
rockiroadsCommented:
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
 
progtwAuthor Commented:
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
 
rockiroadsCommented:
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
 
progtwAuthor Commented:
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
 
rockiroadsCommented:
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
 
progtwAuthor Commented:
'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
 
rockiroadsCommented:
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
 
progtwAuthor Commented:
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
 
progtwAuthor Commented:
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
 
rockiroadsCommented:
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
 
progtwAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 7
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now