Open "\1.txt" For Input As #1 表示以读取方式打开文本文件"1.txt",#1表示文件号,这个号是系统分配的。判断读取文件是否已经到了文件结尾,如下代码:Do While Not EOF(1)'如果不是文件结尾就执行下面语句Input #1, inputFile, myNumber '读取文件数据写入变量inputFileMsgBox i
Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入一个字符。 Debug.Print MyChar ' 显示到立即窗口。 Loop Close #1 下面这个函数可以将文本文件的数据一次读入到一个字符串(但是若包含中文时会出错,因为一个中文字占2个字节)。 Public Function ReadText(FileName As String) Dim ...
'打开文件作为数据输入用,文件号为#1 Do While Not EOF(1) Line Input #1, txt '从已打开的顺序文件中读出一行并将它分配给 String 变量 'Line Input # 语句一次只从文件中读出一个字符,直到遇到回车符 (Chr(13)) '或回车–换行符 (Chr(13) + Chr(10)) 为止。回车–换行符将被跳过,而不会被附加到...
Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入一个字符。 Debug.Print MyChar ' 显示到立即窗口。 Loop Close #1 下面这个函数可以将文本文件的数据一次读入到一个字符串(但是若包含中文时会出错,因为一个中文字占2个字节)。 Public Function ReadText(FileName As String) Dim ...
Do While Not EOF(1) Line Input #1, strr If Left(strr, 2) = "链接" Then txt = txt & vbCrLf & Replace(Replace(strr, "链接:", ""), "提取码:", "---") Else End If Loop Close #1 Open ThisWorkbook.Path & "\输出文件.txt" For Output As #1 Print...
Do While Not EOF(1) '未到达结尾 Line Input #1, s1 '读入一行,放入s1变量中 Loop Close #1 4、LOC 函数 语法:LOC(filenumber) 功能:返回一个 Long,在已打开的文件中指定当前读/写位置。 Dim MyLocation, MyLine Open "TESTFILE" For Binary As #1 ' 打开刚创建的文件。
vba嵌套do while not .eof循环ENdo-while循环 do-while循环和while循环是类似的 区别是do-while是先...
Do While Not EOF(1) ' 循环至文件尾。 Input #1, MyString, MyNumber ' 将数据读入两个变量。 Debug.Print MyString, MyNumber ' 在立即窗口中显示数据。 Loop Close #1 ' 关闭文件。 9、Write # 语句 语法:Write #filenumber, [outputlist] 功能:将数据写入顺序文件。 说明:通常用 Input # 从文件读...
DimMyString, MyNumber Open"TESTFILE"ForInputAs#1 ' Open file for input. Do While Not EOF(1) ' Loop until end of file. Input #1, MyString, MyNumber' Read data into two variables.Debug.Print MyString, MyNumber' Print data to the Immediate window.LoopClose#1 ' Close file. ...
DimTextLine Open"TESTFILE"ForInputAs#1 ' Open file. Do While Not EOF(1) ' Loop until end of file. Line Input #1, TextLine' Read line into variable.Debug.Print TextLine' Print to the Immediate window.LoopClose#1 ' Close file.