Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Issues with recognising USERPROFILE (Vista/Office 2007)

    Hi, can anyone help?

    I have an xml file stored under "Documents" and have code in Word 2007 that loads the file into a domDocument. The filepath I originally had is below (where I experienced no issues):

    C:usersJack21DocumentsData.xml

    but I wish to make this user specific as it needs to be deployed, so have changed the filepath to:

    C:users%USERPROFILE%DocumentsData.xml

    The problem I have is that the file is no longer detected. It appears that %USERPROFILE% is not recognised. Has anyone come across this or is there something wrong with the filepath I have in place.

    Any help greatly appreciated.
    Jack

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Issues with recognising USERPROFILE (Vista/Office 2007)

    Try

    Environ("userprofile") & "DocumentsData.xml"

  3. #3
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Issues with recognising USERPROFILE (Vista/Office 2007)

    Thanks Hans. This was the approach I took in the end and it works fine. Slightly frustrating I cannot set this as a variable, which the other global variables, as I have to place the code within a function to run (well that appears to be the case).

    Regards
    Jack

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Issues with recognising USERPROFILE (Vista/Office 2007)

    Where did you want to use it?

  5. #5
    2 Star Lounger
    Join Date
    Mar 2005
    Location
    Kent, England
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Issues with recognising USERPROFILE (Vista/Office 2007)

    I have set up a number of global variables, together with a fairly large chunk of code, in a file which is stored in StartUp (Generic Code.dot). I have a group of templates that reside in a template area which are linked to Generic Code.dot, which use the global variables on loading.

    When I was testing the functionality I placed a global variable in this area and stored the data file in the Temp folder (Public Const c_strDataFile As String = "C:tempdata.xml"). I did not experience problems with retrieving information from the data file or writing to the data file. This I can only presume is because the string is hard coded. Changing the path to Public Const c_strDataFile as String =" c:users" & Environ("username") & "Documentsdata.xml" does not work when placed with the other global variables - I am assuming that this is because it does not recognise the string.

    Is there a solution that will enable me to set the variable in the global variable location?

    Many thanks
    Jack

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Issues with recognising USERPROFILE (Vista/Office 2007)

    You can't use a function in the definition of a constant. But you can declare a public variable at the top of a module:

    Public strDataFile As String

    and set this when the document containing the code is opened (in an Auto_Open macro or in the Document_Open event procedure in ThisDocument):

    strDataFile = Environ("userprofile") & "Documentsdata.xml"

    It will then be available to the rest of the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •