VBA 读文件和写文件方法

    技术2025-05-28  20

    读文件:

    Function readTextIntoExcel(path As String)   RowIndex = 11   Open path For Input As #1 '   Do While Not EOF(1) '     Line Input #1, currLine     rowDataArr = Split(currLine, Chr(9))’各数据之前以TAB隔开的CSV文件     For i = 0 To UBound(rowDataArr)       Cells(RowIndex, i + 3) = rowDataArr(i)     Next i     RowIndex = RowIndex + 1   Loop   Close #1   Exit Function End Function

    ------------------------------------------------------------------------------------------------

    写文件:

    Function writeInfoIntoTxtFile(fullpath As String)   RowIndex = 11   Open fullpath For Output As #1     Do While Sheet1.Cells(RowIndex, 3) <> ""       Print #1, Sheet1.Cells(RowIndex, 3) & Chr(9) & _                 Sheet1.Cells(RowIndex, 4) & Chr(9) & _                 Sheet1.Cells(RowIndex, 5) & Chr(9) & _                 Sheet1.Cells(RowIndex, 6) & Chr(9) & _                 Sheet1.Cells(RowIndex, 7) & Chr(9) & _                 Sheet1.Cells(RowIndex, 8)       RowIndex = RowIndex + 1     Loop   Close #1 End Function

    最新回复(0)