fork download
  1. Option Explicit
  2.  
  3. Public Sub folder試験()
  4. Dim fullpath As String
  5. fullpath = GetFullPath("D:\goo", "Book1.xlsx")
  6. If fullpath <> "" Then
  7. MsgBox (fullpath)
  8. Else
  9. MsgBox ("該当ファイルなし")
  10. End If
  11. End Sub
  12.  
  13. Private Function GetFullPath(ByVal folder_name As String, ByVal file_name As String) As String
  14. GetFullPath = ""
  15. Dim FSO As Object
  16. Dim full_path As String
  17. Set FSO = CreateObject("Scripting.FileSystemObject")
  18. If find_file(FSO, folder_name, file_name, full_path) = True Then
  19. GetFullPath = full_path
  20. End If
  21. End Function
  22.  
  23. Private Function find_file(FSO As Object, ByVal folder_name As String, ByVal file_name As String, full_path As String) As Boolean
  24. Dim flds As Object
  25. Dim fld As Object
  26. find_file = True
  27. full_path = folder_name & "\" & file_name
  28. If FSO.fileexists(full_path) = True Then
  29. Exit Function
  30. End If
  31. Set flds = FSO.getfolder(folder_name).subfolders
  32. For Each fld In flds
  33. If find_file(FSO, folder_name & "\" & fld.name, file_name, full_path) = True Then
  34. Exit Function
  35. End If
  36. Next
  37. find_file = False
  38. End Function
  39.  
  40.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty