VBA中实现Txt文本内容切分,贴到excel中cell列中
※Txt文件中的内容是从DB中导出的文本数据。在Excel中做数据对比时,找出相应的差分。
同时,VBA中while语句的Break功能的实现。
‘#子函数定义’
private sub subReadDBTxt(FileName as String)
Dim StarRng As Range '定义Excel中粘贴的开始位置
Dim txtPath as String, nextLine As string
Dim WriteFlg As Boolean, OpenFlg as Boolean
Dim i%, j%
Dim sheetName as string
'txtPath=“C:\test\abcdefg.txt”
Open FileName For Input As #1
WriteFlg = False
OpenFlg = False
Do while Not EOF(1)
on Error Resume Next
Line input #1, nextLine
if nextLine = "" then
WriteFlg = False
OpenFlg = False
goto CONTINUE
end if
if InStr(nextLIne, "sheet1") > 0 then
sheetName="sheet1"
goto CONTINUE
elseif InStr(nextLIne, "sheet2") > 0 then
sheetName="sheet2"
goto CONTINUE
End If
if InStr(nextLIne, "----------------------"