Excel VBA code snippet to list or get shared folder names on the specified path and save data to Excel.
This piece of code can also be used on network shared folders provided the network permission allows.
==================================
Sub GetFolderNames()
Dim i, fso, xfolder, xsubFolders, xdata, xgetFolderName, xPath
'xPath = "\\My_Network_Path\My_Folder"
xPath = "c:\my_folder\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set xfolder = fso.GetFolder(xPath)
Set xsubFolders = xfolder.SubFolders
i = 0
xdata = ""
For Each xgetFolderName In xsubFolders
xdata = xPath & xgetFolderName.Name
i = i + 1
Cells(i, 3).Value = xdata
Next
MsgBox ("Total Number of Folders: " & i)
End Sub
==================================
Cheers!!!
Unfortunately it doesn't work for root path (\\My_Network_Path\), you have to insert also "My_Folder".
ReplyDeleteIt depends whether you have the rights to access the root path.
Delete