潇云幕雨
2017-04-14 09:44
采纳率: 100%
浏览 1.1k
已采纳

word ,vba 读取xml 的问题

Function SetDataValue(strXML As String)
Dim MyXmlDoc As MSXML2.DOMDocument40
Dim XmlNode As MSXML2.IXMLDOMNode

On Error Resume Next
ActiveDocument.Shapes("Txt_xml").TextFrame.TextRange.Text = strXML

Set MyXmlDoc = New MSXML2.DOMDocument40
MyXmlDoc.async = False

If MyXmlDoc.LoadXML(strXML) Then
Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Common/DocClass")
If Not (XmlNode Is Nothing) Then
SetDocClass XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Special/Stock/TradeName")
If Not (XmlNode Is Nothing) Then
  SetIndustry XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Common/Title")
If Not (XmlNode Is Nothing) Then
  SetTitle XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Special/Stock/InvestRating")
If Not (XmlNode Is Nothing) Then
  SetEst XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Special/Stock/TargetPrice")
If Not (XmlNode Is Nothing) Then
  SetTargetPrice XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Common/CreateTime")
If Not (XmlNode Is Nothing) Then
  SetDate XmlNode.Text
End If

Set XmlNode = MyXmlDoc.SelectSingleNode("/TemplateData/Common/Author")
If Not (XmlNode Is Nothing) Then
  SetAnalyst XmlNode.Text
End If

Else
Application.StatusBar = "数据格式错误,无法填充。"
End If
SetTitle "dingwei2009"
SetDataValue = "cg"
End Function

SetDocClass ,SetTitle 之类都是 设置word文档的值,但是读取xml却是null,代码能编译,在windows service 2012 上 是什么问题

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 潇云幕雨 2017-04-17 08:07
    已采纳

    自己帮自己回答,因为是word 2016 vba 的引用必须是msxml6.dll

    点赞 打赏 评论
  • devmiao 2017-04-14 15:53
    点赞 打赏 评论

相关推荐 更多相似问题