Quick Background: I write excel macros for a company that uses shared drives on the network to share information between employees
The Problem: Different employees have the same shared drive listed under separate letters. For example Susie has the “Commissions Shared Drive” as drive “Z” but Betty has it as drive “x”.
I’ll design a macro that two different people use and the macro runs into errors because they have separate drive letters. To put it simply, the file locations written in the code won’t be correct for both people due to the difference of drive letter.
The Current Solution: I currently have a copy of the exact same macro with changes made to the file locations to account for the difference of drive letter. This is annoying because anytime I make changes to the one file I have to ensure the other is exactly the same.
The Question: Is there a way I can account for different drive letters in one macro so I don’t have to have duplicates of the file with different addresses?
Thanks in Advance!
-Mike
Use the actual network path.
For instance instead of something like
Use
As long as the user has access to the path, the code will find it regardless of drive mapping.
Edit:
You can view this question and its answers for some great reasons why you should not use the mapped drive letters in your code.
As a side note, if you were using something less updatable then an Excel macro, it would be a good idea to not actually store the path in your code at all. Instead you would have a file that the code views to obtain the path. Thereby what you write will work far longer without having to be recompiled or revised. But again, since you’re just doing an Excel macro I see no compelling reason not to use the direct path.