用VBA将XML字符串格式转换为Excel

用VBA将XML字符串格式转换为Excel,xml,vba,excel,Xml,Vba,Excel,我试图提取下面查询的结果,但是当它到达XML字符串[已处理的数据]时,它无法在Excel中显示结果。有人能帮忙吗?谢谢 Public Sub Load_Error() Dim ADOC As New ADODB.Connection Dim SQL1 As String Dim rst1 As New ADODB.Recordset Dim i As Integer Dim r As Integer '#### Server Information Server_Name = "A" Data

我试图提取下面查询的结果,但是当它到达XML字符串[已处理的数据]时,它无法在Excel中显示结果。有人能帮忙吗?谢谢

Public Sub Load_Error()
Dim ADOC As New ADODB.Connection
Dim SQL1 As String
Dim rst1 As New ADODB.Recordset
Dim i As Integer
Dim r As Integer

'#### Server Information
Server_Name = "A"
Database_Name = "B"

'#### Server Connection is opened

Worksheets("Load Errors").Activate

r = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Range(Cells(1, 1), Cells(r, 6)).ClearContents

ADOC.Open "Provider=MSDASQL.1;DRIVER=SQL Server;SERVER=" & Server_Name & ";DATABASE=" & Database_Name & ";Trusted_Connection=Yes"

SQL1 = "SELECT [CreatedDate],[RecordStatus],[Comment], CONVERT(varchar(max),[ProcessedData]) as [Error Message], [DataExceptionID], [SessionID] " & _
" FROM [C].[dbo].[D](nolock) " & _
" where CreatedDate >= DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) and comment not in  ('FrontierPositionRecon Load Errors','Errors', 'MCAP load errors') " & _
" order by createddate asc "

ADOC.CommandTimeout = 600
Set rst1 = ADOC.Execute(SQL1)

ActiveSheet.Cells(2, 1).CopyFromRecordset rst1
For i = 0 To rst1.Fields.Count - 1
    ActiveSheet.Cells(1, i + 1).Value = rst1.Fields(i).Name
Next

Set rst1 = Nothing
Set ADOC = Nothing


End Sub

不知道为什么,但如果你更换

设置rst1=ADOC.Execute(SQL1)

rst1.opensql1、ADOC、adOpenStatic


它可以工作。

不知道为什么,但是如果你更换

设置rst1=ADOC.Execute(SQL1)

rst1.opensql1、ADOC、adOpenStatic


它可以工作。

所以它可以运行,没有错误,也没有数据返回时的记录计数是多少?正确,无错误。前三列都有数据,但它不会为xml列或其右侧的两列返回任何内容。此查询通常返回大约30-40行。xml字符串通常约为400个字符。感谢它运行,没有错误,也没有数据返回时的记录计数是多少?正确,无错误。前三列都有数据,但它不会为xml列或其右侧的两列返回任何内容。此查询通常返回大约30-40行。xml字符串通常约为400个字符。谢谢