Необходимо посчитать число строк в файле .csv и записать в переменную. Прикладываю сэмпл файла.
Удалось найти такой код:
Код |
---|
Function Count_Lines(FilePath As String) As Long
Dim fsoFile As Scripting.FileSystemObject
Dim fsStream As Scripting.TextStream
'Create a new File system Object
Set fsoFile = New Scripting.FileSystemObject
'Open the file for reading
Set fsStream = fsoFile.OpenTextFile(Filename:=FilePath, IOMode:=ForReading)
'Move to the bottom of the file
Do Until fsStream.AtEndOfStream
fsStream.SkipLine
Loop
'Return the current line number,
'Which will equal the count as
'we are at the end of the file
Count_Lines = fsStream.Line
'Clear Object Variables
Set fsStream = Nothing
Set fsoFile = Nothing
End Function
|
При вызове функции Count_Lines ("C:\tmp\sample.csv") выпадает ошибка "Compile error: User-defined type not" и подсвечивается часть второй строки "fsoFile As Scripting.FileSystemObject".
Почему функция не отрабатывает ?