I would like to list the files in a given folder on the network.
I am getting an error on "dir1" where "Set objFolder = objFSO.GetFolder(dir1)":
"Path not found"
but the path exists!
Code
Sub ListNetwork()
Dim objFolder As Object
Dim objFile As Object
Dim objFSO As Object
Dim f(6) As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
f(1)="\\Computer2\mypath\folder\"
dir1 = f(1)
Set objFolder = objFSO.GetFolder(dir1)
'Loop through the Files collection
For Each objFile In objFolder.Files
n = n + 1
file1(n) = objFile.Name
Cells(n + 3, 2) = file1(n)
Next
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
Display More
[COLOR="#FF0000"][/COLOR]MODERATOR EDIT
Please use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window.
I’ve added them this time but please comply in the future