问题
I'm creating a dropdown list on open that populates the user's mapped network drives (drive letter) and any network locations (folder shortcut). Basically what you would see in the Network Locations section of My Computer/This PC.
Using VBA I know you can sift through mapped drives using the filescripting object but I've been unsuccessful getting network locations.
Trying the Wscript.Network object with the Object.enumNetworkDrives appeared to work fine at work yet doesn't appear to bring in the network locations while at home working remote.
Is there a different, better and/or more consistent method (with a good VBA example) to getting all the mapped drives and network locations using VBA?
回答1:
I suggest you have a look at WMI. Here's a short example to get you started:
Sub ListDrives()
WQL = "Select * From Win32_LogicalDisk"
Set SrvEx = GetObject("winmgmts:root/CIMV2")
Set WMIObj = SrvEx.ExecQuery(WQL)
For Each WMIObjEx In WMIObj
Debug.Print WMIObjEx.Path_.RelPath
Next
End Sub
来源:https://stackoverflow.com/questions/54853165/excel-vba-list-all-mapped-network-drives-and-network-shortcuts-locations