ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

VBA Ãþ¦üdirªº¥\¯à

¦^´_ 1# millerch
­É¥Î samwang ¿ï¨ú dir ³¡¥÷
¦C¥X§A·Q­nªº xlsm ÀÉ
  1. Private fso As Object

  2. Public Sub ListAllXlsmFiles()
  3. Dim foundFiles As New Collection
  4. Dim foundFile As Variant
  5. Dim DirPath As String

  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. Range("A1").Select
  8. With Application.FileDialog(msoFileDialogFolderPicker)
  9.     .InitialFileName = "G:\"
  10.     .Title = "======= ¿ï¾Ü¸ê®Æ§¨ ========"
  11.     .Show
  12.     On Error GoTo EndSub
  13.     DirPath = .SelectedItems(1)
  14. End With

  15. FindAllFiles DirPath, "xlsm", foundFiles

  16. For Each foundFile In foundFiles
  17.     With ActiveCell
  18.         .Value = foundFile
  19.         .Offset(1, 0).Select
  20.     End With
  21. Next foundFile
  22. EndSub:
  23. End Sub

  24. Private Sub FindAllFiles(parentFolder As String, extension As String, foundFiles As Collection)
  25. Dim thisFolder As Object
  26. Dim subFolder As Object
  27. Dim thisFile As Object
  28. Dim testObject As Object

  29. On Error Resume Next
  30. Set thisFolder = fso.GetFolder(parentFolder)

  31. Err.Clear
  32. Set testObject = thisFolder.Files
  33. If Err.Number = 0 Then
  34.     For Each thisFile In thisFolder.Files
  35.         If LCase(thisFile.Name) Like "*." & LCase(extension) Then
  36.             foundFiles.Add thisFile.Path
  37.         End If
  38.     Next thisFile
  39. End If

  40. Err.Clear
  41. Set testObject = thisFolder.SubFolders
  42. If Err.Number = 0 Then
  43.     For Each subFolder In thisFolder.SubFolders
  44.         FindAllFiles subFolder.Path, extension, foundFiles
  45.     Next subFolder
  46. End If
  47. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : Ãø¦æ¯à¦æ¡AÃø±Ë¯à±Ë¡AÃø¬°¯à¬°¡A¤~¯àª@µØ¦Û§Úªº¤H®æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD