kwhw.net
当前位置:首页 >> vBA 读取txt文件 >>

vBA 读取txt文件

Private Sub Command1_Click() Dim txt As String Open "C:\AAA.TXT" For Input As #1 Do While Not EOF(1) Line Input #1, txt MsgBox txt Loop Close #1 End Sub

dim i as,s() interage Open "你的文件路径" For Input As #1 Do Until EOF(1) s(i++)=Input #1,name,id,score '姓名,学号,成绩 Loop for k=0 to i print s(i) ok

Private Sub CommandButton1_Click()Dim filename, inputstring As StringDim i As IntegerDim datai = 1filename = "d:\WYKS.txt" '本列TXT文件放在D盘中Open filename For Input Access Read As #1Do While Not EOF(1)Line Input #1, inputstr...

Sub s() Open ThisWorkbook.Path & "\a.txt" For Input As #1 k = 9 Do While Not EOF(1) Line Input #1, a a = Application.Trim(Replace(a, "--", " ")) Cells(k, 2).Resize(1, 3) = Split(a) k = k + 1 Loop Close #1End Sub

1、直接采用Open函数+Line input命令Private Sub txt_read() Dim txt As String Open "D:\dzh.txt" For Input As #1 ' '对文件做任何 I/O 操作之前都必须先打开文件。Open 语句分配一个缓冲区供文件进行 I/O 之用, '并决定缓冲区所使用的访问方...

用vba去遍历,提取文件名。资料如下供参考 http://club.excelhome.net/thread-1258425-1-1.html 提取txt文件内容,可以通过vba处理

可以使用如下的代码,复制如下代码到VBA模块中运行即可。 如下代码代表4行4列,如果其余行或列数则可更改相应的数字。 具体步骤如下: 打开office excel; Alt+F11打开VBA编辑器; 复制如下代码到模块中; F5运行该模块; 按照提示进行如下步骤...

可以运行下面这段代码,稍加调试一可以达到目标了。 Sub cht() Dim objFSO As Object, objFile As Objectg Dim txtpath As String, cr As Long, ct As String, d As String, allt txtpath = ThisWorkbook.Path & "\text.txt" '该为你自己的路径 ...

Sub 读文本文件() '以下在C盘根目录建立测试文件1.txt Open "c:\1.txt" For Append As #1 '存在打开不存在建立 Print #1, "测试写1行" Print #1, "测试再写1行" Close #1 '关闭文件 '以下读以上建立的文件 Dim txt As String '定义读取用数组 Op...

网站首页 | 网站地图
All rights reserved Powered by www.kwhw.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com