求VBA代码(CSV文件内容导入excel)
CSV文件:类似于QA一览,会有新增的问题,也会对原来的问题进行更新EXCEL文档:字段与CSV文件不一致,且顺序不一致,但是需要获取CSV中存在的字段的值希望有单独的工...
CSV文件:类似于QA一览,会有新增的问题,也会对原来的问题进行更新EXCEL文档:字段与CSV文件不一致,且顺序不一致,但是需要获取CSV中存在的字段的值希望有单独的工具,定期运行,追加数据和更新原因数据
展开
2个回答
展开全部
Sub fMain()
Dim fTextDir As String, rowIndex As Integer, i As Integer
rowIndex = 1:tYesNO=0 'tYesNO为0表示没有首行,如果有改成1
fTextDir = "D:/status.csv" ' csv文本路径
Open fTextDir For Input As #1 ' 导入文本
Do While Not EOF(1) '逐行循环
Line Input #1, currLine '取第一行,并赋值
if tYesNO=0 or rowindex>1 then
rowDataArr = Split(currLine, ",")
For i = 3 To 8
Cells(rowIndex + 1-tYesNO, i + 4).FormulaR1C1 = rowDataArr(i)
Next i
end if
rowIndex = rowIndex + 1
If rowIndex-tYesNo > 15 Then Exit Do
Loop
Close #1
End Sub
Dim fTextDir As String, rowIndex As Integer, i As Integer
rowIndex = 1:tYesNO=0 'tYesNO为0表示没有首行,如果有改成1
fTextDir = "D:/status.csv" ' csv文本路径
Open fTextDir For Input As #1 ' 导入文本
Do While Not EOF(1) '逐行循环
Line Input #1, currLine '取第一行,并赋值
if tYesNO=0 or rowindex>1 then
rowDataArr = Split(currLine, ",")
For i = 3 To 8
Cells(rowIndex + 1-tYesNO, i + 4).FormulaR1C1 = rowDataArr(i)
Next i
end if
rowIndex = rowIndex + 1
If rowIndex-tYesNo > 15 Then Exit Do
Loop
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询