关于vba读取excel文件
2016-02-26 17:19
465 查看
关于vba读取文件夹中的xlxs文件,如下代码就可以实现
//下面这段代码只适合文件夹中只有文件而没有其他文件夹的情况
Sub OpenCloseArray() '把文件夹中的文件看成一个数组,遍历数组即可
Dim MyFile As String
Dim Arr(100) As String
Dim count As Integer
Dim result As Integer
MyFile = Dir("D:\copyxls\" & "*.xlsx")
count = count + 1
Arr(count) = MyFile
Do While MyFile <> ""
MyFile = Dir
If MyFile = "" Then
Exit Do
End If
count = count + 1
Arr(count) = MyFile
Loop
For i = 1 To count
Workbooks.Open Filename:="D:\copyxls\" & Arr(i)
MsgBox Cells(1, 1)
result = result + Cells(1, 1)
ActiveWorkbook.Close savechanges = True
Next
MsgBox result
End Sub
文件夹的路径可以以参数的形式进行传入
//下面这段代码只适合文件夹中只有文件而没有其他文件夹的情况
Sub OpenCloseArray() '把文件夹中的文件看成一个数组,遍历数组即可
Dim MyFile As String
Dim Arr(100) As String
Dim count As Integer
Dim result As Integer
MyFile = Dir("D:\copyxls\" & "*.xlsx")
count = count + 1
Arr(count) = MyFile
Do While MyFile <> ""
MyFile = Dir
If MyFile = "" Then
Exit Do
End If
count = count + 1
Arr(count) = MyFile
Loop
For i = 1 To count
Workbooks.Open Filename:="D:\copyxls\" & Arr(i)
MsgBox Cells(1, 1)
result = result + Cells(1, 1)
ActiveWorkbook.Close savechanges = True
Next
MsgBox result
End Sub
文件夹的路径可以以参数的形式进行传入
相关文章推荐
- vb.net利用webbrowser下载(加载完成判断、多线程、委托)
- VBA 获取Sheet最大行
- VC调用VB DLL
- VBA 入门笔记
- VA、VAO和VBO API备忘
- vbird笔记2016-02-24
- 关于使用VBO渲染
- LCD时序中设计到的VSPW/VBPD/VFPD/HSPW/HBPD/HFPD总结
- QQ Auto Login Visual Basic Script
- OpenGL VBO, PBO与FBO
- vba给数组赋值
- Excel“工程不可查看”及VBA工程密码…
- vb.net如何使用代码给DataGridView…
- vb.net 判断文件编码的方法
- vb.net防止WebBrowser在新窗口中打…
- vs2010 .vb如何生成类库(DLL)
- vb.net webbrowser控件如何获取鼠…
- vb.net DateTimePicker如何显示某…
- 如何使用vb.net多线程
- vb.net多线程同步调用实例