We help IT Professionals succeed at work.

Print a file to the temp directory

douglaskarr
douglaskarr asked
on
272 Views
Last Modified: 2010-05-02
I have a calculation program which writes a temp html document.  I want it to put it in the default temp directory regardless of which OS or computer it's running on.

Here's the problem I ran into.  I wrote the program on a computer with the temp directory in c:\windows\temp - when I ran the program at work it failed since the temp directory was c:\winnt\temp.


Comment
Watch Question

Top Expert 2005

Commented:
Dim sTempPath As String
sTempPath = Environ("TEMP")
Top Expert 2005
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
The temp directory is specified as
ENVIRON("Temp")

As an example, the value in your user's case would be:
c:\winnt\temp

You can use this to build your string.

There are lots of other useful settings you can acces with environ.

To view them,

for i= 1 to 22
  debug.print environ(i)
next i


and look in the immediate debug window

Richard

Commented:
Cross posted again &@*#(S(@!

But maybe you want to put the file in the TMP or USERPROFILE directory...
(Just use the namees listed in the debug.print output)

Richard

Commented:
Cross posted again &@*#(S(@!

But maybe you want to put the file in the TMP or USERPROFILE directory...
(Just use the namees listed in the debug.print output)

Richard

Author

Commented:
Final Code:

Dim sTempPath As String
sTempPath = Environ("TEMP")

Open sTempPath & "\Answer.htm" For Output As #1
....

Worked Great!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.