2、在工程资源管理器中添加一个模块,在模块的“代码”窗口中输入程序代码,如图2所示。具体的程序代码如下所示:
Sub CreatXMLDocument()
Dim xmlDoc1 As New DOMDocument '新建Document文档对象
Dim xmlDoc2 As New DOMDocument '新建Document文档对象
Dim strTemp As String
xmlDoc1.async=False
xmlDoc1.Load ThisWorkbook.Path&"\学生信息.xml" '直接加载XML文档
strTemp=xmlDoc1.XML '保存XML字符串
Debug.Print strTemp '输出XML字符串
xmlDoc2.LoadXML strTemp 'Document对象使用XML字符串加载数据
Debug.Print xmlDoc2.XML '输出XML字符串
Set xmlDoc1=Nothing
Set xmlDoc2=Nothing
End Sub