Excel VBA efficient get file names function

后端 未结 3 645
太阳男子
太阳男子 2021-01-12 05:46

I need to get a collection of file names from a folder on a remote server using VBA in excel 2010. I have a function that works and in the majority of cases it would do the

3条回答
  •  暖寄归人
    2021-01-12 06:21

    This one is lightning fast:

      Sub filesTest()
        Dim x() As String
        x = Function_FileList("YOUR_PATH_AND_FOLDER_NAME")
        Debug.Print Join(x, vbCrLf)
      End Sub
    

    Which calls this function:

     Function Function_FileList(FolderLocation As String)
        Function_FileList = Filter(Split(CreateObject("wscript.shell").exec("cmd /c Dir """ & FolderLocation & """ /b /a-d").stdout.readall, vbCrLf), ".")
     End Function
    

提交回复
热议问题