gpt4 book ai didi

vba - MSXML2.DOMDocument 加载函数在 VBA 中失败

转载 作者:行者123 更新时间:2023-12-02 21:28:44 24 4
gpt4 key购买 nike

我已经为以下问题苦苦挣扎了一段时间,但还没有找到解决方案。

有一个带有 XML 文件的 iShare 页面,我想使用 VBA 代码下载该文件,然后处理该 XML 文件并保存到 MS Access 数据库中。

我已经使用下面的代码大约 4 年了,它运行完美,没有任何问题。但是这周它突然停止工作了。有什么想法吗?

代码:

Private Function GetRequests() As Boolean
On Error GoTo ErrHandler

Dim oDoc As MSXML2.DOMDocument
Dim Url As String
Dim sFileName As String

Set oDoc = New MSXML2.DOMDocument
oDoc.async = False
Url = cUrlDatabase & "/" & cApplicationName & "/In/" & cReqXmlFile

UpdateStatus "Loading " & cReqXmlFile

If Not oDoc.Load(Url) Then
c_sLastError = "Could not load XML " & Url
GoTo EndProc
End If

sFileName = sPath & "\Data\requests.xml"

oDoc.Save sFileName

GetRequests = True
End Function

代码在 oDoc.Load(Url) 部分失败,返回 false。

最佳答案

以下是如何收集错误详细信息的示例:

      Dim xDoc As MSXML.DOMDocument
Set xDoc = New MSXML.DOMDocument

If xDoc.Load("C:\My Documents\cds.xml") Then
' The document loaded successfully.
' Now do something intersting.
Else
' The document failed to load.
Dim strErrText As String
Dim xPE As MSXML.IXMLDOMParseError

' Obtain the ParseError object
Set xPE = xDoc.parseError
With xPE
strErrText = "Your XML Document failed to load" & _
"due the following error." & vbCrLf & _
"Error #: " & .errorCode & ": " & xPE.reason & _
"Line #: " & .Line & vbCrLf & _
"Line Position: " & .linepos & vbCrLf & _
"Position In File: " & .filepos & vbCrLf & _
"Source Text: " & .srcText & vbCrLf & _
"Document URL: " & .url
End With

MsgBox strErrText, vbExclamation End If

Set xPE = Nothing
End If

Example taken from here .

关于vba - MSXML2.DOMDocument 加载函数在 VBA 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22813282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com