VBA中不打开文件读取数据的方法是使用"Open"语句来读取文件内容。以下是一个示例代码: Sub ReadDataFromFile() Dim myFile As String Dim text As String Dim textline As String myFile = "C:\example.txt" ' 文件路径 Open myFile For Input As #1 ' 打开文件 Do Until EOF(1) ' 读取文件内容直到文...
Sub Test0412()Dim I As IntegerDim src As StringI = 1Open "D:\Test.txt" For Input As #1Do Until EOF(1) Line Input #1, src Sheets("ReadFile").Range("A" & I) = src I = I + 1LoopClose #1End Sub 上面代码执行后,发现把txt文本的内容都读到一个格子里面去了,并不是我们想要的结果...
Do While i>1 '条件为True时执行 ... ... '要执行的语句 Loop 2. Do Until i>1 '条件为False时执行 ... ... '要执行的语句 Loop 3. Do ... ... '要执行的语句 Loop While i>1 '条件为True时执行 4. Do ... ... '要执行的语句 Loop Until i>1 '条件为False时执行 5.While...Wen...
31 Set rs = cnn.OpenSchema(adSchemaTables)32 Do Until rs.EOF 33 If LCase(rs!table_name) = LCase(myTable) Then GoTo hhh '如果查到则退出循环 '继续查询 34 rs.MoveNext 35 Loop '释放变量,退出(这是没有查到的情况)36 Set wb = Nothing 37 Set ws = Nothing 38 ...
Do Until rs.EOF ws.Cells(iRow, 1).Value = rs("table_name").Value ws.Cells(iRow, 2).Value = rs("column_name").Value ws.Cells(iRow, 3).Value = rs("data_type").Value iRow = iRow + 1 rs.MoveNext Loop ' 关闭Recordset和数据库连接 ...
3) Do Until EOF(1)Line Input #1, textline text = text & textline Loop 以上代码提取文件的所有内容到text的字符串中。注意是按行提取的。4) Close #1 关闭文件 5)For i = 1 To Len(text)posF = Mid(text, i, 1)If posF = "《" Then UF = i If posF = "》" Then UL = i If...
Do Until EOF(1) '通过line input方法读取文件#1,并赋值给strline变量。一次读取一行。 Line Input #1, strLine ActiveCell = strLine ActiveCell.Offset(1, 0).Select Loop '关闭文件#1--打开的文件一定要关。 Close #1 End Sub Sub WriteToTextFile() ...
②Do Until EOF(1) ③ Line Input #1,src ④ ... ⑤Loop ⑥Close #1 ①把inpath这个文件打开作为#1,inpath是变量,同上面讲述的文件路径一样,就不在赘述,②-⑤做了一个do until循环,循环读取这个文件,直到把文件读完,其中③是核心,逐行来读取数据,把读取到的数据放到src中,src也是自己定义的变量,可以定义...
Do fName = Application.GetSaveAsFilename Loop Until fName <> False NewBook.SaveAs Filename:=fName Application.GetSaveAsFilename为调出标准的“另存为”对话框,获取用户文件名,但并不真正保存任何文件,然后使用代码保存文件。还有Application.GetOpenFileName可以调出标准的“打开”对话框。
Do While Not EOF(FileNumber) Line Input #FileNumber, InputData 'イミディエイトウィンドウへ表示 Debug.Print InputData Loop Close #FileNumber MsgBox "処理が終了しました。", vbInformation End Sub 示例2:Dim intFNum As Integer Dim strExcelDir As String Dim strInputFile As String Dim str...