我在一个文件夹中有多个xml文件(例如100个xml文件),我的要求是创建一个宏来复制xml文件的内容并将其粘贴到excel表中。
例如:第一个xml文件内容 - > Excel单元格A1第二个xml文件内容 - > Excel单元格A2等等。
这将查看给定文件夹中的所有xml文件,然后将内容复制到Sheet1上的列A:
Sub LoopThroughFiles()
Dim MyData As String
Dim LastRow As Long
x = 1
LastRow = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row
Dim StrFile As String
StrFile = Dir("C:\Users\User3282573\*.xml") 'change this path to your folder path
Do While Len(StrFile) > 0
Open "C:\Users\User3282573\" & StrFile For Binary As #1 'also change this path
MyData = Space$(LOF(1))
Get #1, , MyData
Sheet1.Cells(x, 1).Value = MyData
x = x + 1
Close #1
StrFile = Dir
Loop
End Sub