How to detect drive Letter and Open file

Darwin123456

New Member
Joined
Nov 5, 2022
Messages
2
Office Version
  1. 365
  2. 2010
Hi ,

I have some Vba that I am running in a workbook to open another workbook. However my colleagues have different drive letters so when they run the code they get an error, for example the file for me has fileparh Y:\Test\Test.xlsx however for my colleague it is Z:\Test\Test.xlsx.

Is it possible to detect what drive letter they are using and update the file path so they can use the code to open the other workbook?

Thanks in advance for any advice provided.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Too much is unknown about your setup to be definitive, but here's one simple way so long as you can depend upon the VBA CurDir statement to tell you what their drive letter is.

VBA Code:
    Dim OldPath As String, NewPath As String, DriveLetter As String
    
    OldPath = "Y:\Test\Test.xlsx"
    DriveLetter = Left(CurDir, 1)
    NewPath = DriveLetter & Mid(OldPath, 2, Len(OldPath))
 
Upvote 0
@Darwin123456 Welcome.

Maybe set a string variable eg MyPath to modify the user's file path to the parent workbook.
Eg if the parent file is open in Test folder then just
VBA Code:
MyPath = ThisWorkbook.Path & "\Test.xlsx"
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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