0

好吧,开始:我是一个完整的 VBA 傻瓜。我已经尝试破解此代码几个小时了,我认为进一步了解 vba 工作原理的最佳方法是召集军队。我希望没有人因此受到冒犯。

这就是我想要做的事情:a)一个一个地打开一个文件夹中的所有xml文件b)将它们转换为一个excel文件c)然后将它们一个一个地保存为另一个文件夹中的excel文件

我到目前为止的代码如下:

Sub xmltoxl()
Dim fs As FileSearch
Dim i As Integer
Dim wbk As Workbook
Dim s As Integer

Set fs = Application.FileSearch

With fs
    .LookIn = ThisWorkbook.Path
    .Filename = "*.xml"
    For i = 1 To .Execute()
        Set wbk = Workbooks.OpenXML(.FoundFiles(i))
        s = 1
   ChDir "C:\Users\Seeb\Desktop\Volkskrant\2013_archiefb"
    ActiveWorkbook.SaveAs Filename: (s & ".xls")
    s = s + 1
    Next i
End With

End Sub
4

2 回答 2

2

未经测试:

Sub xmltoxl()
Dim f As String
Dim wbk As Workbook
Dim s As Integer

f = Dir(ThisWorkbook.Path & "\*.xml")
s = 0

Do While Len(f)>0
    s = s + 1
    Set wbk = Workbooks.OpenXML(ThisWorkbook.Path & "\" & f)
    wbk.SaveAs Filename:="C:\Users\Seeb\Desktop\Volkskrant\2013_archiefb" & s & ".xls"
    wbk.Close False
    f = Dir() 
Loop


End Sub
于 2013-10-19T00:09:32.440 回答
0

通过一些更改,是的,它起作用了。至少,进行到一半(我只重做下半部分)。谢谢蒂姆。

Sub xmltoxl()
Dim f As String
Dim wbk As Workbook
Dim s As Integer

f = Dir("C:\Users\Seeb\Desktop\Volkskrant\2013_archief" & "\*.xml")
s = 0

Do While Len(f) > 0
    s = s + 1
    Set wbk = Workbooks.OpenXML("C:\Users\Seeb\Desktop\Volkskrant\2013_archief" & "\" & f)
    wbk.SaveAs Filename:="C:\Users\Seeb\Desktop\Volkskrant\2013_archiefb\" & s & ".xls"
    wbk.Close False
    f = Dir()
Loop

结束子

于 2013-10-19T18:49:06.540 回答