ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   File Path (https://www.excelbanter.com/excel-worksheet-functions/250291-file-path.html)

Max2073

File Path
 
Help needed.

I developed a macro that only I used. However, the macro is now required to
be used by others.

The macro opens the required files from my C:\documents and
settings\max28052\ etc - the files are automatically named and saved to
officers c:\documents and settings\"username"\ after being exported from the
corporate database. The file names are always the same regardless of the
officer. The only differences in the file path eg. username.

Is there a way that I can change the marco to selected the required files
from the c:\documents and settings\"username of the logged on user"\help.xls
etc.

Any help would be greatly appreciated.

Kevin Smith[_2_]

File Path
 
Hello,

You can use Environ("UserName").

Change you code from ...

Workbooks.Open Filename:= _
"C:\Documents and Settings\ksmit40\Desktop\IDCplan.xls"

To...

Workbooks.Open Filename:= _
"C:\Documents and Settings\" & Environ("UserName") &
"\Desktop\IDCplan.xls"

--
Kevin Smith :o)


"Max2073" wrote:

Help needed.

I developed a macro that only I used. However, the macro is now required to
be used by others.

The macro opens the required files from my C:\documents and
settings\max28052\ etc - the files are automatically named and saved to
officers c:\documents and settings\"username"\ after being exported from the
corporate database. The file names are always the same regardless of the
officer. The only differences in the file path eg. username.

Is there a way that I can change the marco to selected the required files
from the c:\documents and settings\"username of the logged on user"\help.xls
etc.

Any help would be greatly appreciated.


Harlan Grove[_2_]

File Path
 
Kevin Smith wrote...
You can use Environ("UserName").

Change you code from ...

Workbooks.Open Filename:= _
* * * * "C:\Documents and Settings\ksmit40\Desktop\IDCplan.xls"

To...

Workbooks.Open Filename:= _
* * * * "C:\Documents and Settings\" & _
Environ("UserName") & "\Desktop\IDCplan.xls"

....

Better to use Environ("USERPROFILE") which gives the full profile
directory path and won't need to be changed when/if OP's users upgrade
to Windows Vista or 7 where profiles are stored under C:\Users rather
than C:\Documents and Settings.


All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com