通过VBA中的" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何用<em>vba</em>读取多个excel文档的数据-vba 多个excel文件,vba批

如何用<em>vba</em>读取多个excel文档的数据-vba 多个excel文件,vba批

作者:乔山办公网日期:

返回目录:excel表格制作


录制宏即可做到,点数据-自文件-导入,自带录制的代码即可完美解决,望采纳

通过VBA中的函数sheets(!workbook.worksheet).select,就可以将当前的文件指针指向所选的工作薄中的指定工作表。

参数说明:
workbook为工作簿名即文件名
worksheet为工作表名

当文件指针设定好后,就可以对指定文件的指定工作表进行操作了。
用vba去遍历,提取文件名。资料如下供参考

http://club.excelhome.net/thread-1258425-1-1.html

提取txt文件内容,可以通过vba处理

Sub 按钮e799bee5baa6e79fa5e98193e4b893e5b19e3332_Click()
Application.ScreenUpdating = False
Set cnn = CreateObject("adodb.connection")
[a2:l65536].ClearContents
h = 2
f = Dir(ThisWorkbook.Path & "\*.xls?")
Do While f > ""
If f <> ThisWorkbook.Name Then
cnn.Open "provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;hdr=yes';data source=" & ThisWorkbook.Path & "" & f
Sql = "select * from [sheet1$A1:C1000]"
Cells(h, 1).CopyFromRecordset cnn.Execute(Sql)
h = Cells(Rows.Count, 1).End(xlUp).Row + 1
cnn.Close
End If
f = Dir
Loop
Application.ScreenUpdating = True
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网