Sub kk()
Dim name(20) As String
...
End Sub我想把c:\下面所有xls的文件的文件名放到name(20)中,假设不会超过20,不包括子目录

解决方案 »

  1.   


    Private Sub Command1_Click()
       Call kk("C:\Documents and Settings\Administrator\桌面")
    End SubSub kk(ByVal Path As String)
      Dim cName(20) As String
      Dim cCount As Single
      cCount = 1
      cName(cCount) = Dir(Path & "\*.Xls")
      '如果想取得完全路径用注释的
      'cName(cCount) = Path & "\" & Dir(Path & "\*.Xls")
      'While cName(cCount) <> Path & "\"
      While cName(cCount) <> ""
         cCount = cCount + 1
         cName(cCount) = Dir
         'cName(cCount) = Path & "\" & Dir
      Wend
      
      For i = 1 To cCount - 1
        MsgBox cName(i)
      Next
    End Sub
      

  2.   

    来晚了。用dir函数,第一次用dir(path)返回该目录下查到的第一个文件,以后不带参数调用dir,就可以循环查找所有文件