Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将TXT导入excel,同时跳过前7个字符并移动到每个文件后的下一列_Excel_Vba - Fatal编程技术网

将TXT导入excel,同时跳过前7个字符并移动到每个文件后的下一列

将TXT导入excel,同时跳过前7个字符并移动到每个文件后的下一列,excel,vba,Excel,Vba,亲爱的Stackoverflow会员: 我的脚本仍然缺少一些功能。它需要两个额外的功能: -跳过前7个字符,将行的剩余部分放入单元格。 -完成txt后,向左移动1列并返回第1行 我的脚本如下: 子ReadFilesIntoActiveSheet() 将fso设置为文件系统对象 将文件夹设置为文件夹 将文件设置为文件 将文件文本设置为文本流 将文本行变暗为字符串 将项()设置为字符串 我想我会坚持多久 Dim cl As范围 ' Get a FileSystem object Set fso =

亲爱的Stackoverflow会员:

我的脚本仍然缺少一些功能。它需要两个额外的功能: -跳过前7个字符,将行的剩余部分放入单元格。 -完成txt后,向左移动1列并返回第1行

我的脚本如下:

子ReadFilesIntoActiveSheet() 将fso设置为文件系统对象 将文件夹设置为文件夹 将文件设置为文件 将文件文本设置为文本流 将文本行变暗为字符串 将项()设置为字符串 我想我会坚持多久 Dim cl As范围

' Get a FileSystem object
Set fso = New FileSystemObject

' get the directory you want
Set folder = fso.GetFolder("F:\Google Drive\IBE project - Heamoscan\Data")

' set the starting point to write the data to
Set cl = ActiveSheet.Cells(1, 1)

' Loop thru all files in the folder
For Each file In folder.Files
    ' Open the file
    Set FileText = file.OpenAsTextStream(ForReading)

    ' Read the file one line at a time
    Do While Not FileText.AtEndOfStream
        TextLine = FileText.ReadLine

        ' Parse the line into | delimited pieces
        Items = Split(TextLine, "|")

        ' Put data on one row in active sheet
        For i = 0 To UBound(Items)
            cl.Offset(0, i).Value = Items(i)
        Next
        i = 0
        ' Move to next row
        Set cl = cl.Offset(1, 0)

    Loop

    Set cl = cl.Offset(0, 1)

    ' Clean up
    FileText.Close
Next file

Set FileText = Nothing
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
端接头

欢迎提出任何建议!
非常感谢

您能在循环中使用此功能吗

TextLine = FileText.ReadLine

TrimmedLine = Mid(TextLine, 8)

' Parse the line into | delimited pieces
Items = Split(TrimmedLine, "|")

这似乎对我在excel中的输出没有任何影响。。谢谢你的回复,虽然刚刚把7改成了8。前7个字符是空格吗?在拆分之前,我会使用一个消息框来确认字符数。西蒙,非常感谢你和我一起思考这个问题。然而,我决定使用另一种软件:qlikview。我有一个工作脚本。