Link to home
Create AccountLog in
Avatar of davidsperling
davidsperling

asked on

Environ("HOMEPATH") in Vista/Excel 2007

Code below will output:

sHome=\Users\myusername
sMyFolder=\Users\myusername\KALLE
\Users\myusername exists:False
\Users\myusername\KALLE exists:False

I know that both my home folder and "KALLE" exists. It used to work under windows 2000/Office 2000.

Is there a solution or workaround?


Sub Testi()
    
    Dim fso As New FileSystemObject
    Dim sHome, sMyFolder As String
    sHome = Environ("HOMEPATH")
    sMyFolder = sHome & "\KALLE"
    Debug.Print "sHome=" & sHome
    Debug.Print "sMyFolder=" & sMyFolder
    Debug.Print sHome & " exists:" & fso.FolderExists(sHome)
    Debug.Print sMyFolder & " exists:" & fso.FolderExists(sHome)
        
End Sub

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello davidsperling,

Try:
    sHome = Environ("userprofile")
instead of
    sHome = Environ("HOMEPATH")

Regards,

chris_bottomley
Avatar of davidsperling
davidsperling

ASKER

That will return c:\users\myusername, but that's not correct at the company I'm working at!

The path should be \\domain.company.net\users\myusername\Documents

Is there a way to extract that path?


ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Nop, it doesn't :(
I presume they did before, still might be able to do something if we can get to \\domain.company.net\ somewhere i.e. the default outlook client?

Chris
>>... still might be able to do something if we can get to \\domain.company.net\ somewhere i.e. the default outlook client?

Don't quite understand :)
if for exampel the default mail address will be fred@domain.company.net and teh mail client is outlook then it coul dbe possible to get teh prefix of \\domain.company.net from outlook and continue by adding the path.  Basically if the necessary information can be reliably assembled from any other data, (i.e. 2 or more environment variable) then that will give us a prospective way to achive your needs.

Chris
The answer is it's not possible!
Shame, sorry we couldn't help

Chris