Private Sub Command1_Click()
Dim ShellApp, oPanel, FolderItem1, FolderItem2, oItem
Set ShellApp = CreateObject('Shell.Application')
Set oPanel = ShellApp.NameSpace(0)
Set FolderItem2 = Nothing
For Each FolderItem1 In oPanel.Items
If FolderItem1.Name = '我的电脑' Then
Set FolderItem2 = FolderItem1.Getfolder: Exit For
End If
Debug.Print FolderItem1.Name
Next
If FolderItem2 Is Nothing Then
MsgBox '找不到项目!'
Exit Sub
End If
Set oItem = Nothing
For Each oItem In FolderItem2.Items
Debug.Print oItem.Name
Next
End Sub
输出结果如下:
控制面板
3.5 软盘 (A:)
WINDOWS98 (C:)
程序 (D:)
本地磁盘 (E:)
数据备份 (F:)
光盘 (G:)