Open "c:\示例文件.txt" For Input As #1 Open "c:\示例文件.txt" For Output As #1 Open "c:\示例文件.txt" For Append As #1 Open "c:\示例文件.txt" For Binary As #1 Open "c:\示例文件.txt" For Random As #1 注释:如果打开不止一个文件,把文件号1改成FreeFile,本篇文章都默认读取1个。
1、Open 语句 语法:Open pathname For mode [Access access] [lock] As [#]filenumber [Len=reclength] 其中access、lock、reclength为可选参数,一般不用。 mode 指定打开文件的方式。有5种: Input:以输入方式打开,即读取方式。 Output:以输出方式打开,即写入方式。 Append:以追加方式打开,即添加内容到文件末...
Input 函数只用于以 Input 或 Binary 方式打开的文件。 与Input # 语句不同,Input 函数返回它所读出的所有字符,包括逗号、回车符、空白列、换行符、引号和前导空格等。 示例: Dim MyChar Open "f:\test.txt" For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入...
Input 函数只用于以 Input 或 Binary 方式打开的文件。 与Input # 语句不同,Input 函数返回它所读出的所有字符,包括逗号、回车符、空白列、换行符、引号和前导空格等。 示例: Dim MyChar Open "f:\test.txt" For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入...
Open "E:\nz\work\文章\举例CSV.CSV" For Input As #1 Do While Not EOF(1)Input #1, name, class, num MsgBox name & ", " & class & ", " & num Loop Close #1 End Sub 看看代码截图:程序执行过程:上面的程序首先打开文件“E:\nz\work\文章\举例CSV.CSV”读取数据;并且建立一个Do…While...
#VBA#Private Sub CommandButton1_Click()Dim Str As StringDim textFiles As StringClose #1'关闭已经打开的文件textFiles = ThisWorkbook.Path & "\txt\lineinput.txt"'设置文件以及路径Open textFiles For Input As #1'打开文件Do While Not EOF(1)'循环遍历文件行,如果不是尾行就循环Line Input #1, Str'...
Dim num As Integer Dim zhang As String num = 0 Open "E:\nz\work\文章\人员表单.txt " For Input As #1 Do While Not EOF(1)zhang = Input(1, #1)If zhang = "张" Then num = num + 1 End If Loop If num <> 0 Then MsgBox "表单中姓张的共: " & num & "人!"Else MsgBox "没...
Open "f:/test.txt" For Input As #1 Do While Not EOF(1) ' 循环至文件尾。 MyChar = Input(1, #1) ' 读入一个字符。 Debug.Print MyChar ' 显示到立即窗口。 Loop Close #1下面这个函数可以将文本文件的数据一次读入到一个字符串(但是若包含中文时会出错,因为一个中文字占2个字节)。
Open"TESTFILE"ForInputAs#1 ' Close before reopening in another mode. Close #1 此示例在二进制 (Binary) 模式下打开文件,仅供写操作。 VB Open"TESTFILE"ForBinaryAccess WriteAs#1 ' Close before reopening in another mode. Close #1 下面的示例在随机 (Random) 模式下打开文件。 文件包含用户定义类型的...
Open"TESTFILE"ForBinaryAs#1'打开刚创建的文件。 DoWhileMyLocation<LOF(1)'循环至文件尾。 MyLine=MyLine&Input(1,#1)'读入一个字符到变量中。 MyLocation=Loc(1)'取得当前位置。'在立即窗口中显示。 Debug.PrintMyLine:Tab:MyLocationLoopClose#1'关闭文件。 5、Input#语句 语法:Input#filenumber,varlist...