1.先将你的txt文件放入特定的文件夹,
2.遍历文件夹内的所有文件,
3.打开文件,提取第一与第二行的数据,
如下VBA代码在Excel里面运行,先修改文件夹名称再运行,
Sub programX()
Application.DisplayAlerts = False :
Application.ScreenUpdating = False : ChengXuWenjianMing = ActiveWorkbook.Name
JiLuBiao = ActiveSheet.Name:
Cells.ClearContents
WenJianJiaMingCheng =
"C:\LiangYouFu\ImportantBackup\" '反斜杠不可省略
WenJianMing = Dir(WenJianJiaMingCheng)
Do While WenJianMing <>
""
WenJianMing = Dir
ChuLiShuJu WenJianJiaMingCheng,
WenJianMing, ChengXuWenjianMing, JiLuBiao
Loop
MsgBox "文件遍历结束,请查看数据!
End Sub
Sub ChuLiShuJu(WenJianJiaMingCheng,
WenJianMing, ChengXuWenjianMing, JiLuBiao)
on error resume next
Open WenJianJiaMingCheng &
WenJianMing for input as #1
line input #1,infox
pox = Application.CountA(Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Range("a:a")) + 1
Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Cells(pox, 1) = infox
line input #1,infox
pox = Application.CountA(Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Range("a:a")) + 1
Workbooks(ChengXuWenjianMing).Sheets(JiLuBiao).Cells(pox, 1) = infox
close #1
End Sub
有什么好处呢?
为什么不用xml保存呢?