VBA读取txt文件内容到excel,vba读取txt文件固定位置
时间:2022-08-10 16:02:33
这是前几天一位朋友遇到的一个问题,要对彩/票做一些预测,他从网上导了每一期的开奖数据下来,格式为TXT类型的,存放在一个文件夹里, 需要vba读取txt文件固定位置。如何VBA读取txt文件内容到excel呢?
如下:
其中每份文件的格式都相同,如下:
现在的要求是:把这些数据导入到Excel中去,导入后格式是这样的:
每一期的数据占一列,而且是隔列存放,因为中间空出一列要提取开奖号码的后三位数字,凡是TXT文件名开头是1的就提取到数据源1表中,TXT文件名开头是2的就提取到数据源2表中。
代码如下:
'数据源1--
'提取数据
Sub lmportData()
Dim pat$, i%, r%, data1, data2
pat = ThisWorkbook.Path
Sheets("数据源1").UsedRange.ClearContents
For i = 1 To 6
Open pat & "1-" &i& "查询信息.txt" For Input As #1
r = 1
Do Until EOF(1)
lnput #1, data1, data2
Cells(1,i* 2 - 1)(r,1) = data1
Cells(1,i* 2)(r, 1) = Format(data2, "O00")
r =r + 1
Loop
Close #1
Next
End Sub
标签:vba读取txt文件,VBA读取txt文件内容到excel
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
WPS小技巧—未保存的文档怎么恢复-WPS-记住吧
2023-05-30 07:07:27
怎样在Excel中设置混合条件排序
2023-06-28 06:34:06
![](https://img.aspxhome.com/file/2023/0/37750_0s.png)
Excel中,alt键+小键盘数字的妙用
2022-11-24 15:02:26
![](https://img.aspxhome.com/file/2023/4/a141254_0s.jpg)
Word箭头怎么打?怎么在Word文档里面输入箭头符号?
2022-12-30 08:35:07
![](https://img.aspxhome.com/file/2023/6/31576_0s.jpg)
excel2003自动换行方法
2023-06-23 00:04:18
如何变换Word中文字方向
2023-12-06 15:13:46
![](https://img.aspxhome.com/file/2023/9/19729_0s.jpg)
如何使用Excel函数计算所占的比例
2022-12-01 09:56:22
![](https://img.aspxhome.com/file/2023/0/43020_0s.gif)
excel表格if公式的用法
2022-02-03 10:25:15
Excel中表格自动求积公式的运用方法
2022-03-29 01:52:10
win10软件默认安装路径为C盘_win10怎么更改软件默认安装路径为C盘?
2023-11-01 05:26:48
![](https://img.aspxhome.com/file/2023/4/47694_0s.png)
word中的替换功能也可以当删除键使用
2022-03-01 18:50:52
![](https://img.aspxhome.com/file/2023/6/35556_0s.png)
word文字右上角①如何设置
2023-07-17 07:38:15
![](https://img.aspxhome.com/file/2023/1/32621_0s.png)
excel表格怎么画直线?excel绘制直线及斜线方法
2023-05-01 20:33:58
![](https://img.aspxhome.com/file/2023/4/39794_0s.jpg)
Excel代码教程 模板文件填充数据另存为一个文件
2022-12-14 00:29:22
Word中如何选择文字内容
2022-02-24 22:35:23
![](https://img.aspxhome.com/file/2023/9/32169_0s.png)
如何创建word自定义模板
2023-11-28 16:40:09
![](https://img.aspxhome.com/file/2023/3/17813_0s.jpg)
word文件打不开出现错误怎么办
2022-09-24 11:27:02
Word2007中怎么设置装订线
2023-12-06 15:11:12
![](https://img.aspxhome.com/file/2023/3/19593_0s.gif)
Win10英雄联盟能登陆但进不去游戏黑屏怎么办?
2023-05-30 04:44:40
![](https://img.aspxhome.com/file/2023/2/46322_0s.png)
excel彻底隐藏表格 excel彻底保密表格内容
2023-05-24 08:58:57
![](https://img.aspxhome.com/file/2023/7/a154527_0s.jpg)