通过VBA导入EXCEL的XML不会刷新

时间:2017-02-28 08:19:28

标签: excel vba excel-vba excel-formula excel-2010

我正在尝试通过<?xml version="1.0" encoding="UTF-8"?> <managedAppConfiguration> <version>0.0.1</version> <bundleId>com.foobar.MyApp</bundleId> <dict> <string keyName="configId"> <defaultValue> <value>42</value> </defaultValue> </string> <float keyName="configLatitude"> <defaultValue> <value>50.102549400000001</value> </defaultValue> </float> <float keyName="configLongitude"> <defaultValue> <value>-0.10663980050000001</value> </defaultValue> </float> <string keyName="configString"> <defaultValue> <value>Config-String-Value-Here</value> </defaultValue> </string> </dict> </managedAppConfiguration> XML内容导入到Excel中。

我已尝试录制步骤,macro创建的自动代码如下:

EXCEL VBA

当我再次执行宏时,它只读取标题,并且XML的内容不会加载到Excel中。

请您推荐对代码进行任何调整,以便我可以毫无问题地将XML导入EXCEL?

1 个答案:

答案 0 :(得分:0)

Sub test_user2075017()
    ImportXML "C:\Users\BERAAR1\Desktop\Utilization_matrix\Requests_Weekly.xml"
End Sub

和被叫子:

Sub ImportXML(XML_Path As String)
    Dim wB As Workbook
    Set wB = Workbooks.Open(filename:=XML_Path)
    With wB.Sheets(1)
        .Range(.Range("A1"), _
               .Cells(.Cells(.Rows.count,"A").End(xlUp).Row, _
                      .Cells(1,.Columns.count).End(xlToLeft).Column)).Copy
    End With 'wB.Sheets(1)

    With ThisWorkbook.Sheets("Temp")
        .Cells.Clear
        .Range("A1").Paste
    End With 'ThisWorkbook.Sheets ("Temp")

    MsgBox wB.Name & " was imported in sheet : Temp", vbOKOnly + vbInformation
    wB.Close False
End Sub