[英]Excel macro to copy content of multiple xml files and paste in excel rows
I have a multiple xml files(eg 100 xml files) in a folder, my requirement is to create a macro to copy the content of the xml files and paste it in excel sheet. 我在一个文件夹中有多个xml文件(例如100个xml文件),我的要求是创建一个宏以复制xml文件的内容并将其粘贴到Excel工作表中。
For example: 1st xml file content -> Excel cell A1 2nd xml file content -> Excel cell A2 and so on.. 例如:第一个xml文件内容-> Excel单元格A1第二个xml文件内容-> Excel单元格A2,依此类推。
This will look at all xml files in a given folder and then copy the contents to your column A on Sheet1: 这将查看给定文件夹中的所有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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.