我试图在VBA模块中调用REST Web服务来填充Word文档中的一些书签。由于某种原因,代码在此行冻结
Set cCap1 = ActiveDocument.Bookmarks("CCAP1").Range
cCap1.Text = keyResult.SelectSingleNode("//cCap").Text
说书签“CCAP1”在文档中不存在,实际上在书签列表中完全可见,如您所见
我检查了webservice,它返回了一个有效的XML文档,不会造成任何问题。
您将在下面找到完整的VBA模块代码
Public Static Sub callRestService()
Dim idC As String
Dim custDate As String
Dim query As String
idC = mdlFormVal.getIdC
custDate = mdlFormVal.getCustDate
query = "http://path/to/webservice/service?key=" + idC
Dim keyResult As New MSXML2.DOMDocument60
Dim keyService As New MSXML2.XMLHTTP60
keyService.Open "GET", query, False
keyService.send
keyResult.LoadXML (keyService.responseText)
Dim cRas As Range
Dim cRas1 As Range
Dim cRas2 As Range
Dim cRas3 As Range
Dim cRas4 As Range
Dim cCap As Range
Dim cCap1 As Range
Dim cCap2 As Range
Dim cCf As Range
Dim cCf1 As Range
Dim cInd As Range
Dim cInd1 As Range
Dim cInd2 As Range
Dim cLoc As Range
Dim cLoc1 As Range
Dim cLoc2 As Range
Dim cPIva As Range
Dim cPIva1 As Range
Dim cPrvn As Range
Dim cPrvn1 As Range
Dim cPrvn2 As Range
Dim cusDate As Range
Set cRas = ActiveDocument.Bookmarks("CRAS").Range
cRas.Text = keyResult.SelectSingleNode("//cRas").Text
Set cRas1 = ActiveDocument.Bookmarks("CRAS1").Range
cRas1.Text = keyResult.SelectSingleNode("//cRas").Text
Set cRas2 = ActiveDocument.Bookmarks("CRAS2").Range
cRas2.Text = keyResult.SelectSingleNode("//cRas").Text
Set cRas3 = ActiveDocument.Bookmarks("CRAS3").Range
cRas3.Text = keyResult.SelectSingleNode("//cRas").Text
Set cRas4 = ActiveDocument.Bookmarks("CRAS4").Range
cRas4.Text = keyResult.SelectSingleNode("//cRas").Text
Set cCap = ActiveDocument.Bookmarks("CCAP").Range
cCap.Text = keyResult.SelectSingleNode("//cCap").Text
Set cCap1 = ActiveDocument.Bookmarks("CCAP1").Range
cCap1.Text = keyResult.SelectSingleNode("//cCap").Text
Set cCap2 = ActiveDocument.Bookmarks("CCAP2").Range
cCap2.Text = keyResult.SelectSingleNode("//cCap").Text
Set cCf = ActiveDocument.Bookmarks("CCF").Range
cCf.Text = keyResult.SelectSingleNode("//cCf").Text
Set cCf1 = ActiveDocument.Bookmarks("CCF1").Range
cCf1.Text = keyResult.SelectSingleNode("//cCf").Text
Set cInd = ActiveDocument.Bookmarks("CIND").Range
cInd.Text = keyResult.SelectSingleNode("//cInd").Text
Set cInd1 = ActiveDocument.Bookmarks("CIND1").Range
cInd1.Text = keyResult.SelectSingleNode("//cInd").Text
Set cInd2 = ActiveDocument.Bookmarks("CIND2").Range
cInd2.Text = keyResult.SelectSingleNode("//cInd").Text
Set cLoc = ActiveDocument.Bookmarks("CLOC").Range
cLoc.Text = keyResult.SelectSingleNode("//cLoc").Text
Set cLoc1 = ActiveDocument.Bookmarks("CLOC1").Range
cLoc1.Text = keyResult.SelectSingleNode("//cLoc").Text
Set cLoc2 = ActiveDocument.Bookmarks("CLOC2").Range
cLoc2.Text = keyResult.SelectSingleNode("//cLoc").Text
Set cPIva = ActiveDocument.Bookmarks("CPIVA").Range
cPIva.Text = keyResult.SelectSingleNode("//cPIva").Text
Set cPIva1 = ActiveDocument.Bookmarks("CPIVA1").Range
cPIva1.Text = keyResult.SelectSingleNode("//cPIva").Text
Set cPrvn = ActiveDocument.Bookmarks("CPRVN").Range
cPrvn.Text = keyResult.SelectSingleNode("//cPrvn").Text
Set cPrvn1 = ActiveDocument.Bookmarks("CPRVN1").Range
cPrvn1.Text = keyResult.SelectSingleNode("//cPrvn").Text
Set cPrvn2 = ActiveDocument.Bookmarks("CPRVN2").Range
cPrvn2.Text = keyResult.SelectSingleNode("cPrvn").Text
Set cusDate = ActiveDocument.Bookmarks("CUSTDATE").Range
cusDate.Text = custDate
End Sub
有没有人遇到过这样的事情? 谢谢你的时间。
答案 0 :(得分:0)
我设法解决了这个问题,而且#34;简直就是"重新创建所有文档书签。