vba Office 2013 中的 XML 声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19082405/
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-11 23:33:25  来源:igfitidea点击:

XML declaration in Office 2013

xmlexcelvbams-officeoffice-2013

提问by Braulio

I have the follow VBA code to work with XML using Office 2010:

我有以下 VBA 代码可以使用 Office 2010 处理 XML:

Public xmlDOM As DOMDocument

Public Sub setXML(xmlFileName As String)

    Set xmlDOM = CreateObject("MSXML.DOMDocument")
    xmlDOM.async = False
    xmlDOM.Load xmlFileName

End Sub

OBS: There is a reference set to Microsoft XML, v6.0

OBS:有对 Microsoft XML v6.0 的参考集

BUT if I open the same code on Office 2013 I got an error that the

但是如果我在 Office 2013 上打开相同的代码,我会收到一个错误

Public xmlDOM As DOMDocument

is not declared but there is still the reference to Microsoft XML, v6.0 set.

未声明,但仍有对 Microsoft XML v6.0 集的引用。

if I change

如果我改变

Public xmlDOM As DOMDocument

to

Public xmlDOM As MSXML.DOMDocument60

the compiler accepts but running the code I will get an error in

编译器接受但运行代码我会得到一个错误

Set xmlDOM = CreateObject("MSXML.DOMDocument") 

even if I change it to

即使我将其更改为

Set xmlDOM = CreateObject("MSXML2.DOMDocument60")

OBS: There is a reference set to Microsoft XML, v6.0 in Office 2013

OBS:Office 2013 中有对 Microsoft XML v6.0 的参考集

What is going on?

到底是怎么回事?

回答by Stephenloky

Replace

代替

Public xmlDOM As DOMDocument

with

Public xmlDOM As MSXML2.DOMDocument60

and

Set xmlDOM = CreateObject("MSXML.DOMDocument")

with

Set xmlDOM = New MSXML2.DOMDocument60