设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2003|回复: 4
打印 上一主题 下一主题

[其它] 怎么使用宏代码把TXT文件导到EXCEL里?

[复制链接]
跳转到指定楼层
1#
发表于 2008-12-4 19:50:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
怎么使用宏代码把TXT文件导到EXCEL里?
代码应该怎么去写?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2008-12-4 19:51:04 | 只看该作者

怎么使用宏代码把TXT文件导到EXCEL里?

怎么使用宏代码把TXT文件导到EXCEL里?
代码应该怎么去写?[:32]
3#
发表于 2008-12-4 19:58:09 | 只看该作者
自己试着录制一段,然后再做适当的修改.
4#
发表于 2008-12-5 10:39:34 | 只看该作者
学习微软的东西,很努力!
5#
发表于 2009-5-24 20:04:59 | 只看该作者
Private Sub CommandButton6_Click() ''文件转化
Application.ScreenUpdating = False
Dim m, filesload, froad As String
Dim nfile, i As Integer
Const forreading = 1, forwriting = 2, forappending = 3
Const tristateusedefault = -2, tristatetrue = -1, tristatefalse = 0
Dim fs, f, ts, s
If (ListBox2.ListCount) = 0 Then
MsgBox "没有可选择表执行!"
Exit Sub
End If

Application.DisplayAlerts = False
For nfile = 0 To ListBox2.ListCount - 1
    m = ListBox2.List(nfile)

filesload = Left(ActiveWorkbook.FullName, (Len(ActiveWorkbook.FullName) - Len(ActiveWorkbook.Name)))

froad = filesload & m
'''打开txtfile表
Set fs = CreateObject("scripting.filesystemobject")
Set f = fs.getfile(froad)
Set ts = f.openastextstream(forreading, tristatefalse)
Do While ts.AtEndOfstream <> True
s = ts.readline
i = i + 1

Sheet1.Cells(i, 1) = Trim(s)

Loop
ts.Close


'Workbooks.Open (froad)
'Application.Visible = False
  Next nfile

Application.ScreenUpdating = True
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-18 04:05 , Processed in 0.126362 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表