How to find the class id of an arbitrary object?  Example:Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Posted on 2016-08-04
Medium Priority
Last Modified: 2016-08-27
Please, do not post tangents about whether today's goal is good, bad, fast, slow, brilliant or stupid.  I already had a bunch of those tangents here.  Strangely enough, that long winded discussion never mentioned createobject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")  which I now believe might be a very useful construction.

My goal is to make vba code more portable by switching from early binding to late binding. I wanted to do this for ARBITRARY object types while keeping the object's methods and properties unchanged.  

For instance let us say I want to switch the following code to late binding.

Dim x as dataobject ' reference to ms forms 2.0 object library  which on my machine is c:\windows\syswow64\fm20.dll
set x = new dataobject

I accidentally found a webpage that showed the following alternative.
   dim x as object
  Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

How can intentionally find similar classids? For instance, can I transform the following
    dim x as new SHDocVw.ShellWindows
Question by:rberke
  • 4
  • 3
LVL 72

Accepted Solution

Qlemo earned 1200 total points (awarded by participants)
ID: 41743223
You can search in the registry below HKCR\CLSID for the value containing your class name to replace.
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 800 total points (awarded by participants)
ID: 41743364
I added the "Microsoft Internet Controls" as the fifth Reference in my VB(A)Project.

In the "Immediate" Window:


Author Comment

ID: 41743383
I'll be a son of a gun -- that was really easy !!
To replace MSForms.dataobject I search for "dataobject" and found just what I needed:

        Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.DataObjectClass

Next, I wanted to replace < set x =  New SHDocVw.ShellWindows > so I searched for "ShellWindows"

     (default)  REG_SZ   Shellwindows
     Appid      Reg_SZ   {9BA05972-F6A8-11CF-A442-00A0C90A8F39}

That actually worked in the following

Sub ShowIE()
Dim shellWins As Object, explorer As Object '  SHDocVw.ShellWindows & SHDocVw.InternetExplorer
    Set shellWins = CreateObject("New:{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
    For Each explorer In shellWins
        Debug.Print explorer.LocationURL
End Sub

Open in new window

But, I still have one more question.  What if I had been try to replace   MsForms.Page?  Search for "Page" gives me a dozen false positives before I finally got to
      Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.PageClass

I recognized that as the correct key because I had previously seen the same structure for the DataObject.  That is cheating, I want a methodology that finds an arbitrary object (without relying on previous success searching for a similar object).

Is there some methodology that will quickly get to the correct classId having just the library.class (E.G. SHDocVw.ShellWindows )?
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

LVL 72

Expert Comment

ID: 41743403
Sorry, but I don't think you will succeed in that. Some classes are translated into something more easily to use. "MsForms.Page" certainly is a VB alias for "Microsoft.Vbe.Interop.Forms.PageClass".
But in general, the classes are following the same scheme. "MsForms" translates to "Microsoft.Vbe.Interop.Forms" - always.
"Excel.Application" is a COM reference, and as such has an entry below HKCR\Excel.Application with CLSID pointing to HKCR\CLSID, and that again contains the real class name "Microsoft.Office.Interop.Excel.ApplicationClass". This shows the complexity of your request.

Author Comment

ID: 41743430
I am still making more progress than I expected.  I will leave this question open for while, just in case someone has a better idea.  Then I will award you points.  

Thanks for you help.


Author Comment

ID: 41743468
To replace  set  var = new xxxxx.yyyy
With  Set var = CreateObject("new:{3F4DACA4-160D-11D2-A8E9-00104B365C9F}")

You must first find the “magic numbers”. The following procedure seems to work pretty well.
Open Notepad to be used as workspace.

Open regedit and manuver to HKEY_CLASSES_ROOT\CLSID\
Ctrl f to find in yyyyy.  (remove the checkbox next to Keys and Values, and keep Data)

Edit > Copy Key Name > then paste into notepad.
Edit > Modify > Ctrl C > then paste into notepad. The first entry might look like this
    Class REG_SZ Microsoft.Vbe.Interop.Forms.DataObjectClass

Use F3 to repeat the find and record the next occurances of yyyyy.
If the search “hangs” for over a minute, you are done.
You are also done if the key name does not start with HKEY_CLASSES_ROOT\CLSID

For instance yyyyy = “InternetExplorer” might look like this

Summarize all the class ids and ignore duplicates.  
Eliminate incorrect class ids using code like this.

Sub test711()
On Error Resume Next
Dim x1 As SHDocVw.InternetExplorer ' your original early binding class
Dim x2 As Object
Dim x3 As Object
Set x2 = CreateObject("new:{0002DF01-0000-0000-C000-000000000046}") ' possible replacement
Set x3 = CreateObject("new:{xxxxxxx.....xxxx}") ' another possible replacement

Debug.Print TypeName(x1) & vbCrLf & TypeName(x2) & vbCrLf & TypeName(x3)

End Sub

Author Comment

ID: 41763088
I still believe there might be a more general answer and (when I have time) I am going to open a new question to pursue a general resolution to my question.
For instance, I am very intrigued by Fanpage's code which shows the GuiId associated with a referenced library.    Perhaps there is some way of diving lower into the reference and pull out all class names and their associated clsid?

But, for right now, I agree the question should be closed.

Qlemo should get best answer

300 Points should go to Qlemo, and 200 to Fanpages.
LVL 72

Expert Comment

ID: 41765117
OP stated a different point distribution, so stopping the closing process.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

586 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