View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default ActiveX Control Combo Box

Again, this code requires a reference to the MS WMI Scripting Library.

Bernie


Sub IdentifyDriveLetterAndTypes()
Dim colDisks As SWbemObjectSet
Dim objDisk As SWbemObject

Set colDisks = GetObject( _
"Winmgmts:").ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk In colDisks
UserForm1.ComboBox1.AddItem _
objDisk.DeviceID & " - " & DriveMessage(objDisk.driveType)
Next objDisk

Load UserForm1
UserForm1.Show
End Sub

Function DriveMessage(myType) As String

Select Case myType
Case 1
DriveMessage = "Drive type could not be determined."
Case 2
DriveMessage = "Removable drive"
Case 3
DriveMessage = "Local hard disk"
Case 4
DriveMessage = "Network disk"
Case 5
DriveMessage = "Compact disk"
Case 6
DriveMessage = "RAM disk"
Case Else
DriveMessage = "Drive type could not be determined."
End Select

End Function

"K" wrote in message
...
On Feb 16, 3:52 pm, Kenneth Hobson
wrote:
Add the reference as commented.
Private Sub ComboBox1_GotFocus()
ComboBox1.List = DriveList
End Sub

Function DriveList() As Variant
'add, Tools References... Microsoft Scipting Runtime
Dim fso As New FileSystemObject
Dim dic As New Scripting.Dictionary
Dim d As Object
For Each d In fso.Drives
dic.Add d.driveletter, vbNullString
Next d
DriveList = dic.Keys
End Function


Thanks for replying kenneth, your code is perfect but just small
question that your code is giving just the drives letters but if i
want letters and their names or description like ("F:\ [Home drive]")
etc then how can i get that.