Manipulate/copy .CSV data, without opening the file?

后端 未结 2 1258
不思量自难忘°
不思量自难忘° 2021-01-26 07:20

I\'m trying to optimize some code that takes some test data stored in CSV files does some analysis and copies their data into an excel sheet. This code is often run on hundreds

2条回答
  •  不思量自难忘°
    2021-01-26 08:04

    I would open them as text rather than workbooks:

    Sub ReadCSV()
        Dim MyString As String
        Open "C:\path\text.csv" For Input As #1 ' Open file for input. 
        Do While Not EOF(1) ' Loop until end of file.
            Line Input #1, MyString ' Read a line into variable
            Debug.Print MyString ' Print data to the Immediate window.
        Loop
        Close #1 ' Close file.
    
    End Sub
    

    This will be much faster than opening as a workbook

提交回复
热议问题