我编写了一些从我们的服务器检索文本并将该文本写入 Word 文档的代码。
我们正在将我们的办公套件从 2007 年升级到 2013 年,但是在 Word 2013 中测试我以前工作的代码时遇到了问题。
我已将其范围缩小到该http.send
行,这似乎没有发送任何内容。当我在 2007 套件上运行代码时,我稍等片刻,然后它跳转到http_OnResponseFinished()
Sub,但在 2013 套件中它不会进入那个 sub。
URL 是正确的,并且在 2007 和 2013 套件之间看起来相同/返回相同的数据。
Public Sub Download(Url As String, Optional Async As Boolean = True)
Debug.Print "About to download text from url '" & Url & "'."
http.Open "GET", Url, True 'http must be opened before it can send the request
http.SetRequestHeader "Content-type", "application/json"
http.Send 'Sends the request
' If Wait Then
' http.WaitForResponse
' End If
End Sub
Private Sub http_OnResponseFinished()
Dim Response As String
Response = http.ResponseText
WriteTextToWord Response
Finished = True
Debug.Print "Completed downloading and inserting text, icons and links."
If err <> 0 Then
Call writeToLog(err.Description)
End If
End Sub