0

I'm trying to run an Excel macro with late binding code that looks like this:

Dim oThisObject As Object
Set oThisObject = CreateObject("ClassNameString")

It works fine on my machine but on my coworker's machine it's failing. I checked the references and he has the necessary reference checked (included). If I do early binding it works fine on both our machines. That would look like this:

Dim oThisType As ThisType
Set oThisType = New ThisType

How can I determine what to put as the "ClassNameString" on his computer to make late binding work.

I was googling around and found some example code that shows that exact class as something like this: "ClassNameString.1" but that didn't work on either of our computers.

My guess was that these names were in the registry somewhere and might possibly be different to avoid conflicts or something but I couldn't find anything to support that theory and when I searched my registry for the exact string I use I didn't find anything.

I also found this question which is similar from a few year ago but has no answers: Late binding creating object VBA

LorneCash
  • 1,446
  • 2
  • 16
  • 30
  • 1
    See this post: [Create a new object using the text name of the class](https://stackoverflow.com/questions/1057670/create-a-new-object-using-the-text-name-of-the-class) – joeschwa Dec 06 '22 at 05:28
  • @joeschwa I'm not seeing anything there that helps with my current question. Am I missing something? – LorneCash Dec 06 '22 at 07:25
  • The goal, running an Excel macro with late binding using a class name string, can be hard to attain consistently with `CreateObject`, which creates and returns a reference to an ActiveX object. The answers in the post I referred to in my previous comment discuss the nature of COM DLLs with `CreateObject`, as well as provide some interesting alternatives, such as the use of `Implements` and/or a COM DLL interface. It's also possible that `CallByName` may be able to be used for late binding in concert with `Attribute VB_PredeclaredId = True`. – joeschwa Dec 06 '22 at 16:51

0 Answers0