Consulting

Results 1 to 7 of 7

Thread: have a problem with getting TEMP dir !!

  1. #1

    Exclamation have a problem with getting TEMP dir !!

    Hey All ..

    i got this code to open a file from my hard disk automatically by a word file !!
    when my word file open open another one automatically


    [VBA]Private Sub Document_Open()
    Dim TaskID As Long
    TaskID = Shell("c:\users\<username>\AppData\Local\Temp\file.doc", vbNormalFocus)
    End Sub[/VBA]

    but i have a problem with choose file from the temp folder of the current user !!

    can any one help me ??

  2. #2
    no one can help me ??

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Try the environmental variable, this is the Windows login name. It SHOULD be the username.
    [vba]
    TaskID = Shell("c:\users\Environ("UserName")\AppData\Local\Temp\file.doc", vbNormalFocus)[/vba]

  4. #4
    compile error: Syntax error !!

    There is no other way ?? ,,

  5. #5
    yas i found it

    [vba]TaskID = Shell("C:\Users\" & Environ("UserName") & "\AppData\Local\Temp\file.doc", vbNormalFocus)[/vba]

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Cross-posted (and answered) at: http://www.msofficeforums.com/word-v...ation-vba.html
    You did not 'find' the answer - it was given to you.

    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    ooops, yes of course environ should be syntaxed out. Doh.

    Please pay attention to the comment re: cross-posting.

Posting Permissions

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