成语大全网 - 汉语词典 - 关于VBA的DIR搜索后缀名的问题

关于VBA的DIR搜索后缀名的问题

Sub cc()

Dim MyPath As String, MyName As String, TName() As String

MyPath = "D:\"

MyName = MyPath & "*.xls"

n = CreateObject("Scripting.FileSystemObject").GetFolder(MyPath).Files.Count

ReDim TName(1 To n)

MyName = Dir(MyName)

i = 0

Do While MyName <> ""

if instr(MyName,"xls") then

i = i + 1

TName(i) = MyName

end if

MyName = Dir

Loop

End Sub