现一文件夹内有近百个word文档,每一个word文件都是以类似354、355、356的形式命名,我需要按文件名大小批量提取其中的数据,忽略掉提取数据环节,请问我该怎么才能用VBA按顺序读取所有文档呢?
非常感谢你的回答,可以写一段代码吗?就以354、355、356为文件名。麻烦了。
追答看你私信,代码我先私信你,怕这里发了提交不上。
Private Function MyFunction8()
Dim Path As String, Spath As String
Dim Arr(), N As Long, Str As String
Path = "D:\新建文件夹\" '路径 注意后面要有斜杠
Spath = Dir(Path & "*.doc") '要查找的文件后缀名
Do While Len(Spath) '循环读取文件
N = N + 1
ReDim Preserve Arr(1 To N) '重新定义数组范围
Arr(UBound(Arr)) = Spath '将文件名转换为数值以进行排序
Spath = Dir() '查找下一个文件
DoEvents
Loop
Call Paixu(Arr()) '调用排序函数
For I = 1 To UBound(Arr) '依次取出排序后文件
Str = Str & Arr(I) & vbCrLf
Next
MsgBox Str
End Function
Private Function Paixu(ByRef Arr()) '冒泡法排序
For I = UBound(Arr) To LBound(Arr) Step -1
For J = LBound(Arr) To I - 1
If Val(Arr(I)) < Val(Arr(J)) Then
Temp = Arr(I)
Arr(I) = Arr(J)
Arr(J) = Temp
End If
Next
Next
End Function