PDA

View Full Version : [SOLVED] Missing Microsoft Common Dialog Control



MichaelH
11-20-2004, 10:05 AM
Hi Guys,
I want to use the Color Dialog on a User Form and get the selected colour no, but I don't have the Microsoft Common Dialog Control loaded.

When I bring up the Additional Controls panel (from the User Form code window, Tools / Additional Controls) it doesn't list the Microsoft Common Dialog so I can't select it to install it.

I've found that the Control is COMDLG32.ocx but I don't have one of these in my Windows/System32 folder (I do have a COMDLG32.dll).

How can I get the Common Control to appear in the AdditionalControls panel?

I'm using WinXP and OfficeXP.

Thanks

Michael

Zack Barresse
11-20-2004, 01:42 PM
Hello Michael,

If you have missing controls, I believe this is due in part (most likely) to an incomplete installation. I would try reinstalling Excel with all of it's components. And are you sure it's not 'comctrl32.ocx'? I've uploaded the ocx file that may be the one you are looking for. Not sure if they will work or not, but it's worth a shot.

..

Zack Barresse
11-20-2004, 01:44 PM
Here is the 'comdlg32.dll'.

..

MichaelH
11-22-2004, 05:51 AM
Thanks Zack,

I'll let you know how I get on.

cheers

Michael
.
.
.
Later
I already had the dll, it was the ocx that I couldn't find.
a. I did a detect and repair on Office XP but this didn't fix.
b. I scouted around the internet a bit more and it looks like the ocx is ony for VB not VBA, the latter uses the dll so it should have worked.
c. however, it looks like you have to be licensed to be able to use the dll via having VB developer edition or similar, which I don't have,
d. I found something re Office 97 that said you needed to have ActiveX controls at the time you installed Office 97, but I don't remember anything about this in XP.
e. I'm concluding that I'm not going to be able to get at the Common Dialog Control ,

unless someone else has an idea?

thanks

Michael:bawl

Zack Barresse
11-22-2004, 01:25 PM
Michael,

Did you try registering the dll? As discussed here (http://www.vbaexpress.com/forum/showthread.php?t=493&highlight=register):


How about:

regsvr32.exe [path\file.dll]

From the commandprompt

MichaelH
11-23-2004, 04:05 AM
Cheers Zack,

This is what I got trying to register the dll:

C:\windows\system32\comdlg32.dll was loaded, but the DllRegisterServer entry point was not found.
This file can not be registered.


So I'm still stuck

Thanks

Michael

Ivan F Moala
11-25-2004, 03:55 AM
You don't need the control, besides which inserting this control in a userform creates extra overhead pls users will need this ocx registered.



Option Explicit
'// Ivan F Moala
'// http://www.XcelFiles.com
'// 16th June 2002

Private Type CHOOSECOLOUR
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function ChooseColorA _
Lib "Comdlg32" ( _
lpChooseColor As CHOOSECOLOUR) _
As Long
Declare Function FindWindowA _
Lib "User32" ( _
ByVal lpClassName As Any, _
ByVal lpWindowName As String) _
As Long

Function SelectColour(Code_RGB) As Boolean
Dim CColor As CHOOSECOLOUR
Dim CustColors As String * 16
With CColor
.lStructSize = 36
.hwndOwner = FindWindowA(vbNullString, Application.Caption)
.lpCustColors = CustColors
.flags = 2
End With
If ChooseColorA(CColor) = 0 Then Exit Function
Code_RGB = CColor.rgbResult
SelectColour = True
End Function

Sub Tester()
Dim Code_RGB As Long
If Not SelectColour(Code_RGB) Then Exit Sub
MsgBox "The RGB code you chose:=" & Code_RGB & vbCr & _
"Red:=" & RGBRed(Code_RGB) & vbCr & _
"Green:=" & RGBGreen(Code_RGB) & vbCr & _
"Blue:=" & RGBBlue(Code_RGB)
'// Activecell colour
'ActiveCell.Interior.Color = Code_RGB
'// OR Selection
Selection.Interior.Color = Code_RGB
End Sub

Public Function RGBRed(RGBCol As Long) As Integer
'// Return the Red component from an RGB Coloor
RGBRed = RGBCol And &HFF
End Function

Public Function RGBGreen(RGBCol As Long) As Integer
'// Return the Green component from an RGB Colour
RGBGreen = ((RGBCol And &H100FF00) / &H100)
End Function

Public Function RGBBlue(RGBCol As Long) As Integer
'// Return the Blue component from an RGB Colour
RGBBlue = (RGBCol And &HFF0000) / &H10000
End Function


OR


Sub Kolour()
Application.Dialogs(xlDialogPatterns).Show
End Sub

MichaelH
11-25-2004, 04:16 AM
Ivan,
Thank you for your advice, I'll try your code later.
I'm just starting out on VBA so still have a long way to go.
One of the reasons I wanted to get the Common Dialog working was so that I can easily get to and have control of e.g. Print options, Save As options etc.
I've done more digging on the net and there are lots of examples using the Common Dialog control, but only one referred to needing the VB Developer s/w so I thought there must be a simpler solution.
Anyway, I've found some sample code for Save As so with yours I'm building a library.

Many thanks again, I think we'll call this closed.

Cheers
Michael