声明早期绑定的 MSXML 对象会在 VBA 中引发错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11245733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:24:59  来源:igfitidea点击:

Declaring early bound MSXML object throws an error in VBA

excelvbascriptingmsxml

提问by user1486889

I am trying to import xml data into excel.. So the first line of the code is

我正在尝试将 xml 数据导入 excel .. 所以代码的第一行是

Dim XMLDOC As MSXML2.DOMDocument

Dim XMLDOC As MSXML2.DOMDocument

and this gives an error "user defined type not defined"

这给出了一个错误“用户定义的类型未定义”

回答by Scott Holtzman

Inside the VBE, Go to Tools -> References, then Select Microsoft XML, v6.0 (or whatever your latest is. This will give you access to the XML Object Library.

在 VBE 中,转到 Tools -> References,然后选择 Microsoft XML, v6.0(或任何最新版本。这将允许您访问 XML 对象库。

Updated with fancy pic!

更新了精美的图片!

enter image description here

在此处输入图片说明

回答by Joshua Duxbury

I had DOMDocumentdefined which needed Microsoft XML, v3.0but I had Microsoft XML, v6.0selected in references which caused the below error

我已经DOMDocument定义了哪些需要,Microsoft XML, v3.0但我Microsoft XML, v6.0在参考文献中选择了导致以下错误

"user defined type not defined".

“未定义用户定义的类型”。

The solution

解决方案

The solution was to either change DOMDocumentto DOMDocument60(60 uses ver 6.0) or use the Microsoft XML, v3.0reference with DomDocument.

解决方案是更改DOMDocumentDOMDocument60(60 次使用 6.0 版)或使用Microsoft XML, v3.0带有DomDocument.



Just a quick note, if anyone is using a different version, such as Microsoft XML, v4.0, then DOMDocument40should be used. This is because the number at the end of the DOMDocumentis specific to the version of the library being used.

只是一个简短的说明,如果有人使用不同的版本,例如 Microsoft XML,v4.0,那么DOMDocument40应该使用。这是因为末尾的数字DOMDocument特定于正在使用的库的版本。

回答by Chanel

I work with a VBA Excel Macro that someone else wrote and I was tasked with fixing it after recently upgrading from Windows 7 / Office 2010 to Windows 10 / Office 2016. I started to receive the same "user defined type not defined" compile error. My previous install also had MS XML v6.0 but apparently you have to specifically point to this version in your code on Windows 10 and/or Office 2016 (I wasn't able to confirm which upgrade caused the issue). I was able to resolve the issue by doing a Find/Replace on the following:

我使用其他人编写的 VBA Excel 宏,最近从 Windows 7 / Office 2010 升级到 Windows 10 / Office 2016 后,我的任务是修复它。我开始收到相同的“用户定义类型未定义”编译错误。我之前的安装也有 MS XML v6.0,但显然你必须在 Windows 10 和/或 Office 2016 上的代码中特别指出这个版本(我无法确认是哪个升级导致了问题)。我能够通过对以下内容执行查找/替换来解决该问题:

"DOMDocument" to "MSXML2.DOMDocument60"
"XMLHTTP" to "MSXML2.XMLHTTP60"

回答by Abdelhameed Mahmoud

I am using Microsoft Windows 10 & Office 2016.

我使用的是 Microsoft Windows 10 和 Office 2016。

Using Microsoft XML 6.0does not fix the problem.

使用Microsoft XML 6.0不能解决该问题。

Selecting Microsoft XML 3.0fixed the compilation error

选择 Microsoft XML 3.0修复了编译错误

Microsoft XML 3.0 reference

Microsoft XML 3.0 参考

回答by yradov

I had the 3rd and 6th versions installed, and the project uses the 4th one. I installed the 4th version from https://www.microsoft.com/en-us/download/details.aspx?id=15697and this solved the problem.

我安装了第 3 个和第 6 个版本,项目使用第 4 个版本。我从https://www.microsoft.com/en-us/download/details.aspx?id=15697安装了第四个版本,这解决了问题。