声明早期绑定的 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
Declaring early bound MSXML object throws an error in VBA
提问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!
更新了精美的图片!
回答by Joshua Duxbury
I had DOMDocument
defined which needed Microsoft XML, v3.0
but I had Microsoft XML, v6.0
selected 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 DOMDocument
to DOMDocument60
(60 uses ver 6.0) or use the Microsoft XML, v3.0
reference with DomDocument
.
解决方案是更改DOMDocument
为DOMDocument60
(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 DOMDocument40
should be used. This is because the number at the end of the DOMDocument
is 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
回答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安装了第四个版本,这解决了问题。