Код на VBA

1 отговора 0 прегледа
#1

Код на VBA

Как мога да преброя броя на записите в текстов файл.

Отговор
в отговор на Heзнaeщ #2

Re: Код на VBA


Option Explicit
Sub CountLinesFile()
Dim ResultStr As String
Dim FileName As String
Dim FileNum As Integer
Dim Counter As Double

FileName = InputBox("Please enter the Text File's name, e.g. test.txt")
'Check for no entry
If FileName = "" Then End
'Get Next Available File Handle Number
FileNum = FreeFile()
'Open Text File For Input
Open FileName For Input As #FileNum
'Turn Screen Updating Off
Application.ScreenUpdating = False
'Set The Counter to 1
Counter = 0
'Loop Until the End Of File Is Reached
Do While Seek(FileNum) <= LOF(FileNum)
'Store One Line Of Text From File To Variable
Line Input #FileNum, ResultStr
'Increment the Counter By 1
Counter = Counter + 1

'Start Again At Top Of 'Do While' Statement
Loop
'Close The Open Text File
Close
'Remove Message From Status Bar
MsgBox ("Row = " & Counter)

End Sub

Редактирано от TRN на

Отговор