User Path - relative paths on work computer vs on home computer

-1

I work on two PC's one at home and one at work. The user name for my home pc is Mike. for work it is mmcloughlin. I have a text file that is located at C:\Users\Mike\Dropbox on my home computer. On my work computer the same file is located at c:\users\mmcloughlin\dropbox . When I run a Macro script to access that file, it throws an error when i am on my work computer. It is expecting mike instead of mmcloughlin. How do i "fool" the script into finding the file both at the mike location and at the mmcloughlin location?

Michael McLoughlin

Posted 2018-09-17T00:49:51.317

Reputation: 1

Is this a VBA macro used for example in Excel or Word? – angelofdev – 2018-09-17T00:55:07.907

Why is the capitalization inconsistent for folders and filenames (i.e. Dropbox versus dropbox )? If you used consistent capitalization, then a user environment variable for the path to the HOME folder would be a quick and simple solution. – sawdust – 2018-09-17T01:29:28.347

Answers

0

You’ll need to use an environment variable that always points to your profile folder.

In this case, %HOMEPATH%, should work.

For your script you will use the path, %HOMEPATH%\Dropbox.

%HOMEPATH% points to C:\users\<your username> on Windows. Unless the profiles folder has been moved. But that’s the beauty of environment variables. It doesn’t matter where the user profile is stored.

It is usually not a good practice to hard code values in to your programs, unless you specifically want it to work in only one environment. Use environment variables when you can so that your programs always work, regardless of the changing environment.

Appleoddity

Posted 2018-09-17T00:49:51.317

Reputation: 9 360