Determine drive

  • Thread starter Thread starter WLMPilot
  • Start date Start date
W

WLMPilot

Is there a way to determine what drive is assigned to my memory stick.
Instead of having to "explore", then drag and drop my spreadsheets between my
computer and memory stick, I want to use a command button to save it to the
memory stick.

Thanks,
Les
 
Ok, maybe I was not clear enough. I want to know if there is a code in VBA
(Excel) that can automatically determine what drive letter is assigned to the
memory stick so when I click the command button (Caption="Save To Memory
Stick"), it will know what drive to send it to.

Les
 
Dave Peterson said:

I think that sample code does not distinguish between memory sticks and
external disks. Maybe it would be simpler to rename the memory stick (if
possible) and check for volume name, something like this:

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set colDrives = fso.Drives

For Each objDrive In colDrives
If objDrive.IsReady Then
If objDrive.VolumeName = "MYUSBDRIVE" Then
Debug.Print objDrive.Path, _
objDrive.VolumeName, _
objDrive.DriveType
End If
End If
Next

or using WMI:

Set WMI = GetObject _
("WinMgmts:Root\Cimv2")

Set colLogicalDisks = WMI.ExecQuery _
("Select * From Win32_LogicalDisk " & _
"Where VolumeName = 'MyUSBDrive'")

For Each objLogicalDisk In colLogicalDisks
Debug.Print objLogicalDisk.DeviceID, _
objLogicalDisk.VolumeName, _
objLogicalDisk.Description
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top