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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码