Consulting

Results 1 to 5 of 5

Thread: Solved: directing VBA code to view current user's My Documents folder as data source

  1. #1
    VBAX Regular jeeves's Avatar
    Joined
    Jan 2005
    Location
    Canada
    Posts
    14
    Location

    Solved: directing VBA code to view current user's My Documents folder as data source

    Hi there everyone...
    Any help on this would be appreciated.

    A while back, I had to customize an OTB third party application to work with our existing mail merge code (also customized, from yet another vendor).

    Basically:
    customization 1 allows user to select contacts and exports them to a csv file that is a hardcoded filename and location in c:\program files...
    customization 2 then looks to the hardcoded csv file location and uses the exported data to place contact names in our existing letter, memo, etc templates.

    But now, in order to allow for yet another customization, I need to direct both sets of code to write to the the My Documents folder of the current user.

    Can anyone give me any hints on how to do this? I'm not even sure where to start...
    do you bite your ice cream?

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    The user profile path is available as an Environment variable through the Environ function, so you can do this[VBA]Dim strUserDocPath As String

    strUserDocPath = Environ("USERPROFILE") & "\My Documents"[/VBA]
    K :-)

  3. #3
    VBAX Regular jeeves's Avatar
    Joined
    Jan 2005
    Location
    Canada
    Posts
    14
    Location
    thank you! this worked. i'll mark this as solved.
    do you bite your ice cream?

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    If you're getting variable not defined, have you missed the quotes?

    Yes, you could use the documents path but environ is better and should work.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    Environ is one of the most powerfull functions that I know of to retrieve operating system environment info in a easy way.

    Use this excellent KB to see what tresures it holds:
    http://vbaexpress.com/kb/getarticle.php?kb_id=762

    HTH,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

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