关于 VB6 / VBA 中 CreateObject() 的问题

发布于 2024-07-10 01:25:27 字数 288 浏览 10 评论 0原文

我可以这样做:

Dim fso As New FileSystemObject

或者我可以这样做:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

我如何知道 CreateObject 使用什么字符串? 例如,我怎么知道要使用“脚本”。 “Scripting.FileSystemObject”的一部分? 你去哪里查找?

I can do this:

Dim fso As New FileSystemObject

or I can do this:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

How do I know what string to use for CreateObject? For example, how would I know to use the "Scripting." part of "Scripting.FileSystemObject"? Where do you go to look that up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨落星ぅ辰 2024-07-17 01:25:34

我首先在 MSDN 库中搜索 FileSystemObject http://msdn.microsoft.com/library

该站点充满了文档,包括如何调用 CreateObject 的详细信息。

I would start by searching for FileSystemObject in the MSDN library at http://msdn.microsoft.com/library

The site is chock full of documentation, including the details of how to call CreateObject.

骷髅 2024-07-17 01:25:33

使用 VB6 IDE,选择“项目”、“引用”,然后选择引用“Microsoft Scripting Runtime”。

如果您不知道该引用的名称,可以使用“引用”对话框的“浏览”按钮来选择文件 /system 32/scrrun.dll。

选择参考后,关闭“参考”对话框,然后打开“对象浏览器”(“视图”菜单)。 将下拉列表更改为最有可能的候选者,即“脚本”。 这将显示库的类,其中之一是“FileSystemObject”。 因此,您会发现 CreateObject 所需的字符串是“Scripting.FileSystemObject”。

如果您不知道引用名称或文件名,但知道类名,那么您可以在注册表中搜索“FileSystemObject”,很快就会发现您需要的完全限定名称是“Scripting.FileSystemObject” 。

Using the VB6 IDE, choose Project, References, then to pick the reference 'Microsoft Scripting Runtime'.

If you didn't know what the reference is called, you could use the References dialog's Browse button to pick the file /system 32/scrrun.dll.

With the reference chosen, close the References dialog then open the Object Browser (View menu). Change the dropdown to the most likely candidate, being 'Scripting'. This will reveal the library's classes, one of which is 'FileSystemObject'. Hence, you will have discovered the the string required for CreateObject is 'Scripting.FileSystemObject'.

If you didn't know the Reference name or the file name but you did know the class name then you could search the registry for "FileSystemObject" and it should soon be revealed that the fully-qualified name you require is 'Scripting.FileSystemObject'.

绮烟 2024-07-17 01:25:32

它是在 Windows 注册表中的 HKCR 密钥下注册的组件的 ProgID

HKEY_CLASSES_ROOT\Scripting.FileSystemObject

ProgID 是人类可读的COM 对象的标识符。 它们指向实际的 CLSID,在本例中为:

HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}

您可以在此处找到包含组件实现的实际 COM .dll。

在您提供的第一个示例代码中,您正在执行早期绑定,在第二个示例代码中,您正在执行后期绑定。

It is the ProgID of the component which is registered in Windows registry under HKCR key:

HKEY_CLASSES_ROOT\Scripting.FileSystemObject

ProgID's are human readable identifiers for COM objects. They point to the actual CLSIDs, which in this case is:

HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}

This is the place where you can find the actual COM .dll that includes the implementation of the component.

In the first sample code you have provided you are doing an early-binding, and in the second one you are doing a late-binding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文