Judgedread
New Member
- Joined
- Apr 16, 2014
- Messages
- 16
Hello,
I'm trying to test if some files in a specific folder exists before opening them.
So my thoughts was to list all documents from that folder, look-up if the value exist or not and then continue the script.
Here is a script I found but somehow the path "https://...." is not recognized (it works fine if I put "C:\")
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("https://teamsite.company.com/sites/002981/User_Access/Team%20Documents/Reporting/LSA%20Activities/Statistics")
ws.Cells(1, 6).Value = "The files found in " & objFolder.Name & "are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
any idea ?
Thanks a lot !!
Cheers
I'm trying to test if some files in a specific folder exists before opening them.
So my thoughts was to list all documents from that folder, look-up if the value exist or not and then continue the script.
Here is a script I found but somehow the path "https://...." is not recognized (it works fine if I put "C:\")
Sub ListAllFile()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder("https://teamsite.company.com/sites/002981/User_Access/Team%20Documents/Reporting/LSA%20Activities/Statistics")
ws.Cells(1, 6).Value = "The files found in " & objFolder.Name & "are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
Next
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
any idea ?
Thanks a lot !!
Cheers