How to find name of for a late binding reference

Viewed 198

I'm trying to bullet proof an application I've written in Excel. In order to do so, I want to add late binding references whenever possible. Unfortunately, I do not know how to determine what the correct name is that I should be using for all references.

For example the File System Object can be referenced thus....

Dim oFs as Object
Set oFs = CreateObject("Scripting.FileSystemObject")

I can find out that "Scripting.FileSystemObject" is the correct name to use without googling by going to Microsoft's document page here. But no such page exists for the Object Library reference. So how can I find out what the correct name is for "Microsoft Office 16.0 Object Library"?

1 Answers

When you use CreateObject on Scripting.FileSystem, you're creating a FileSystem object. The class that defines a FileSystem object is in the Scripting type library. In other words, you're not creating a Scripting object. (I'm pretty sure you know this, I'm just setting up the next part.)

If there were any objects in the Office type library, you could create them using

CreateObject("Office.SomeObject")

but there aren't any objects in there, so there's nothing to create. If you search the registry for the label that you see in Tools - References (like Microsoft Office 16.0 Object Library) you can see a Primary Interop Assembly Name. I always thought that the first part of that name was what you use in CreateObject, but now I'm not sure. If you search for Excel 16.0 Object Library, you can see that the first section of its interop name is Excel. And if you want to late bind Excel, you'd use Excel.Application. But when I try to find the interop name for scrrun.dll, I can't find it. It has to be in the registry, but searching for just "Scripting" would take a lifetime.

Since there aren't any objects in Office, there's nothing to create. But what is in that typlib are constants and enums. To late-bind those you just declare variables or create your own enums.

In short, you don't need to create an Office object and I'm no help on where the authoritative source is for the string to pass to CreateObject (but I'm still betting on registry). If you find it, let us know.

Related