0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VBA3

Posted at

Function ReadCSV(ByVal filePath As String) As Variant
Dim fso As Object
Dim ts As Object
Dim content As String
Dim lines() As String
Dim lineCount As Long
Dim i As Long

' Create FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file with Shift-JIS encoding
Set ts = fso.OpenTextFile(filePath, 1, False, -1)

' Count the number of lines in the file
lineCount = 0
Do While Not ts.AtEndOfStream
    ts.ReadLine
    lineCount = lineCount + 1
Loop

' Close and reopen the file to reset the position
ts.Close
Set ts = fso.OpenTextFile(filePath, 1, False, -1)

' Read the file content line by line
ReDim lines(1 To lineCount)
For i = 1 To lineCount
    lines(i) = ts.ReadLine
Next i

' Close the file
ts.Close

ReadCSV = lines

End Function

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?