请问用VBA如何将TXT档中的数据导入EXCLE表中,谢谢
请问如何将TXT档中的数据导入EXCLE表中,谢谢
TXT档案如下:
序号=N1
刀把=MWLNR2525M08
刀片=CNMG120408
转速=1200
进给=0.2
序号=N2
刀把=MWLNR2525M08
刀片=CNMG120408
转速=1000
进给=0.2
序号=N3
刀把=MWLNR2525M08
刀片=CNMG120408
转速=1200
进给=0.1
序号=N4
刀把=MWLNR2525M08
刀片=CNMG120408
转速=1300
进给=0.3
......
EXCLE档如下:
序号刀把 刀片 转速 进给
1N1MWLNR2525M08CNMG12040812000.2
2N2MWLNR2525M08CNMG12040810000.2
3N3MWLNR2525M08CNMG12040810000.2
4N4MWLNR2525M08CNMG12040812000.1
5N5MWLNR2525M08CNMG12040813000.3
[解决办法]
Sub InputData() Dim Arr, Ary, k%, i%, m% Open Application.GetOpenFilename("文本文件,*.txt", , "请选择", , False) For Input As #1 Arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf): Reset ReDim Ary(1 To 5, 1 To 1) For k = 0 To UBound(Arr) If Arr(k) Like "序号*" Then i = i + 1 ReDim Preserve Ary(1 To 5, 1 To i) For m = 1 To 5 Ary(m, i) = Split(Arr(k + m - 1), "=")(1) Next End If Next [A2].Resize(i, 5) = Application.Transpose(Ary)End Sub