PDA

View Full Version : have a problem with getting TEMP dir !!



ximpostor
10-11-2012, 12:51 PM
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


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

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

can any one help me ?? :think:

ximpostor
10-11-2012, 03:44 PM
no one can help me ??

fumei
10-11-2012, 04:45 PM
Try the environmental variable, this is the Windows login name. It SHOULD be the username.

TaskID = Shell("c:\users\Environ("UserName")\AppData\Local\Temp\file.doc", vbNormalFocus)

ximpostor
10-12-2012, 07:51 AM
compile error: Syntax error !!

There is no other way ?? :( ,,

ximpostor
10-12-2012, 10:24 AM
yas i found it

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

macropod
10-12-2012, 12:38 PM
Cross-posted (and answered) at: http://www.msofficeforums.com/word-vba/14672-problem-documents-folder-location-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

fumei
10-12-2012, 01:24 PM
ooops, yes of course environ should be syntaxed out. Doh.

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