嗨,我正在做家庭作业,并且想在组合框中填充所有窗口驱动器列表。当我从cambox中选择驱动器名称时,该文件夹/子文件夹应在列表框中列出。
我已经在组合框中填充了驱动器名称,这是我的代码: enter image description here
Private Sub Form_Load()
Dim fso As FileSystemObject
Dim d As Drive
Dim dName As String
Dim k As String
Dim g As String
Set fso = CreateObject("Scripting.Filesystemobject")
For Each d In fso.Drives
k = d.DriveLetter
dName = dName & "," & d
Next d
g = Mid(dName, 2, Len(dName))
cboDrive.RowSource = g
End Sub
答案 0 :(得分:0)
这会将所有网络驱动器输出到立即窗口,因此您只需更改Debug.Print
位即可将其添加到组合框中。
Sub All_Drives()
Dim oNtwrk As Object
Dim oDrvs As Object
Dim x As Long
Set oNtwrk = CreateObject("WScript.Network")
Set oDrvs = oNtwrk.EnumNetworkDrives
For x = 0 To oDrvs.Count - 1 'Step 2 'Might need step 2... can't remember.
Debug.Print oDrvs.Item(x)
Next x
End Sub