我一直在使用以下代码从Web读取文本文件:
'import the text file into a string
Function DownloadTextFile(URL As String) As String
On Error GoTo Err_GetFromWebpage
Dim objWeb As Object
Dim strXML As String
' Instantiate an instance of the web object
Set objWeb = CreateObject("Microsoft.XMLHTTP")
' Pass the URL to the web object, and send the request
objWeb.Open "GET", URL, False
objWeb.send
' Look at the HTML string returned
strXML = objWeb.responseText
DownloadTextFile = strXML
End_GetFromWebpage:
' Clean up after ourselves!
Set objWeb = Nothing
Exit Function
Err_GetFromWebpage:
' Just in case there's an error!
MsgBox Err.Description & " (" & Err.Number & ")"
Resume End_GetFromWebpage
End Function
第一次它工作得很好,但是当我对文本文件进行更改时,它不会反映在返回的字符串中。就好像excel正在缓存文件一样。我能做什么来解决这个问题?谢谢!
最佳答案
如果没有URL
就不可能对其进行测试,但是您是否尝试过将setRequestHeader与no-cache一起使用?
例子:
objWeb.setRequestHeader "Content-Type", "text/xml"
objWeb.setRequestHeader "Cache-Control", "no-cache"
objWeb.setRequestHeader "Pragma", "no-cache"