Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 检查txt文件中以特定单词开头的行,并统计出现的行数_Vba_Excel_Count - Fatal编程技术网

Vba 检查txt文件中以特定单词开头的行,并统计出现的行数

Vba 检查txt文件中以特定单词开头的行,并统计出现的行数,vba,excel,count,Vba,Excel,Count,我一直在检查给定的txt文件是否有以特定单词开头的行。然后我想数一数以这个词开头的行数。虽然我不能完全正确,但我确实认为我与支票有点接近。非常感谢您的任何帮助! 这是到目前为止我的代码 .Pattern = "(\nC_PIN\s)(\b\d\b\s)" .Global = True Set objFil3 = objFSO.OpenTextFile(inFileName) If objFil3.IsMatch(inFileName) Then MsgBox "File OK" Else:

我一直在检查给定的txt文件是否有以特定单词开头的行。然后我想数一数以这个词开头的行数。虽然我不能完全正确,但我确实认为我与支票有点接近。非常感谢您的任何帮助! 这是到目前为止我的代码

.Pattern = "(\nC_PIN\s)(\b\d\b\s)"
.Global = True
Set objFil3 = objFSO.OpenTextFile(inFileName)
If objFil3.IsMatch(inFileName) Then
 MsgBox "File OK"

Else: MsgBox "Wrong file type chosen. Please check directory"
End If

Robert,对对象变量使用
.ReadLine
方法

Dim numLines as Long: numLInes = 0
Dim strSearch as string '## the value you're searching for
strSearch = "Steve!"    '## MOdify as needed
Do While Not objfil3.AtEndofStream
    If Left(objfil3.ReadLine, Len(strSearch)) = strSearch Then
        numLines = numLines + 1
    Else:

    End If
Loop
    MsgBox objFil3 & " contains " & numLines & " beginning with " & strSearch

我得到了一个Expceted-End-Of-Statement错误,用于
Do,而不是EOF处的objfil3
Try-revised方法,如上所述。我是凭记忆做的,所以如果不起作用,请告诉我。复习时没有错误,但我明天会做测试,谢谢。
ReadLine
方法读取流的每一行。我已经仔细检查过,这是该方法的正确语法。