Flash drive directory access

erutherford

Active Member
Joined
Dec 19, 2016
Messages
449
I have excel files located on a flash drive. The directory assigned letter (D:) for the drive changes depending on which computer I am using. This causes some code to stop working. Is there a solution that allows me to keep using the flash drive?

thanks in advance
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This might solve my problem if I can get it work.

VBA Code:
Sub Openflashdrive()

Dim strFile As String
strFile = Application.GetOpenFilename(FileFilter:="Excel files, *.xlsm", Title:="Choose regdwnld file")

End Sub
The dialog box opens and I can select the file, it just doesn't open the file. has to be something simple.
 
Upvote 0
First, I would NOT work on a file on a flash/usb drive if that's what you're doing, having experienced loss of the file due to corruption. These are meant for storage only.
Use the relative path property in your code, not C: or whatever it is you're using, or transfer the file to the same C: drive folder in every instance.
 
Upvote 0
First, I would NOT work on a file on a flash/usb drive if that's what you're doing, having experienced loss of the file due to corruption. These are meant for storage only.
Use the relative path property in your code, not C: or whatever it is you're using, or transfer the file to the same C: drive folder in every instance.
Good advice! BTW do you see anything in that code that won't allow the file to open?
 
Upvote 0
That function/method only gets the name of the file to open, it doesn't open files. You could add
Workbooks.Open strFile

or use file picker as noted.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,833
Messages
6,121,861
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top