Dutch Gemini's Weblog Pages

December 23, 2010

VBA cannot create MSComDlg.CommonDialog ActiveX

Filed under: Excel,Programming,Setup,VBA,Windows — dutchgemini @ 12:53 pm

Within an application I’m developing for Excel (version doesn’t matter) I use the Microsoft Common Dialog Control, version 6 (SP6), contained in COMDLG32.OCX. For some reason I did not want to put the control on a UserForm and I decided to use it with late binding in my code.

So far so good, the application ran like a charm, and everyone in my office environment was happy with it.

However, when we started distributing the application to other people, it all of a sudden stopped working and the common dialog never popped up and of course, nobody could save or open files.

After investigation, I found out that this statement didn’t work:

Dim cDlg As Object
Set cDlg = VBA.CreateObject("MSComDlg.CommonDialog")

To my surprise, I got a run-time error 429 stating ActiveX component can’t create object. First I thought it was missing but this was not the case (you will find it on every PC). I tried to re-register the component but without success.

In short, and after a lot of googling, I found out that on the failing PC there wasn’t a problem with the component but with the permissions of this component. This particular component can be used in a custom application only if properly licensed and Microsoft provides the license for this component only if you are running a developer’s version of Office or of Visual Studio (and indeed in my office all PCs have). Of course, installing such edition together with my application or asking my customers to buy one was not an option for me and I had to find another solution.

Although Microsoft caused me trouble but they also provided me with a solution.

It turns out that these “component-licenses” are stored in the Registry, in particularly under the key named HKCR\Licenses. Each licensed component has its own sub-key —unfortunately with no correspondence with the CLSID of the component— and a license string stored in the (Default) item.

After some trial-and-error I was able to isolate the key used by the Common Dialog (see below) and after adding it to the PC where my application was failing I finally got everything working again, making me a happy camper.

To add the license information for the Common Dialog copy the next section to a text file, save it with a “.REG” extension and merge it into the Registry (I do this via InnoSetup):

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Licenses]
@="Licensing: Copying the keys may be a violation of established copyrights."
[HKEY_CLASSES_ROOT\Licenses\4D553650-6ABE-11cf-8ADB-00AA00C00905]
@="gfjmrfkfifkmkfffrlmmgmhmnlulkmfmqkqj"

I must remind that messing with the Registry can cause trouble and that creating entries under the “Licenses” key may be a violation of established copyrights, and for that purpose I have added the first line in the above text (copied from my PC’s registry).

Dutch.

9 Comments »

  1. just the ticket! thanks!

    Comment by andy — January 27, 2012 @ 4:21 pm | Reply

  2. this didn’t work for me (windows 2003 std server)

    Comment by kevin — February 9, 2012 @ 2:19 am | Reply

    • In a similar situation, the problem was solved by re-registering this file: “C:\WINDOWS\System32\MSCOMCTL.OCX”. Of course, this goes without any guarantee of success. I have found out that not all common control components are available by default on Windows 2003 Server, and also not on on Vista, 7 or Server 2008. The common dialog may have dependencies to these. What I suggest is that you verify if all components contained in the VB6Runtime package are installed.

      Comment by dutchgemini — February 9, 2012 @ 9:27 am | Reply

  3. phew…..that fixed my err 429, you are a star, many thanks

    Comment by John — May 27, 2012 @ 3:14 pm | Reply

  4. This totally saved me, THANKS! I thought the problem was related to my 64bit Windows 7 where files need to be in the SysWOW64 folder and registered via CMD as Administrator. This solved the problem for previous OCX files but not for my current problem. The registry file made ALL the difference and my old faithful APP was running again.

    Comment by Fred — August 28, 2012 @ 12:08 am | Reply

  5. THAAAAAANKS A LOT, YOU SAVE MY LIFE!

    Comment by guuus — September 5, 2012 @ 6:03 pm | Reply

  6. can u plz explain how to merge it with registry?

    Comment by TDP — July 26, 2013 @ 10:21 pm | Reply

    • Do as it says: «To add the license information for the Common Dialog copy the next section to a text file, save it with a “.REG” extension and merge it into the Registry.». The “next section” are the few lines in fixed (non-proportional) font. Merging into the registry is done by running (double-click in Explorer) the saved “.REG” file. As a programmer I expect you can do this without additional instructions.

      Comment by dutchgemini — August 5, 2013 @ 10:01 am | Reply

  7. thanks , thanks , thanks…

    Comment by farhad — February 3, 2019 @ 1:57 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a reply to TDP Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a free website or blog at WordPress.com.