|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 my6730c 于 2019-11-13 12:00 编辑
Sub import_from_txt3()
Sheets("利润表-当期").Activate
Dim file_name As String, my_path As String
Dim lines, cols
Dim i As Integer, j As Integer, k As Integer, q As Integer
Application.ScreenUpdating = False
Worksheets("利润表-当期").Range("A1:K150").ClearContents
my_path = ThisWorkbook.Path
file_name = "3.txt"
'读取文件
Open my_path & "\" & file_name For Input As #1
lines = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
k = UBound(lines) + 1 '文件的行数
'遍历每一行
For i = 1 To k
cols = Split(lines(i - 1), "|") '以逗号作为分隔,将每行字符分割,分隔符可根据实际情况自己修改
q = UBound(cols) + 1 '分隔成的列数
For j = 1 To q '遍历该行的每一列
Worksheets("利润表-当期").Cells(i, j) = cols(j - 1) '输出到表格中
Next
Next
Application.ScreenUpdating = True
End Sub
标红的代码 只用了一个分隔符,我想再加一个分隔符 tab 如何加???求各位大佬指教
|
|