2
votes

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
Why do you want to late-bind this library? - BigBen
To try and eliminate errors that might popup for users that use earlier excel versions. I’m using it in an import function i wrote that suppresses code from being executed. - rohrl77
What specifically are you using from that library that would not be compatible with earlier versions? - BigBen
Specifically I want to ensure that ´MsoAutomationSecurity´ works. I import data from other workbooks that have code in the OnOpen procedure (that i don't want to run). That said, I'm not entirely sure that the error that I'm seeing comes from that reference. I want to switch it to late binding mostly to eliminate it as a problem source. - rohrl77
What is the error you're seeing? This may be an XY problem. - BigBen

1 Answers

2
votes

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.