Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing text file using Excel VBA

Status
Not open for further replies.

MMund

Programmer
Oct 9, 2007
57
CA
Years ago, before I started working for my current employer, an Excel VBA app was written that writes a text file to the user's C:\ . When I hired on, this was one of many apps for which I assumed responsibility. The program has worked with little in the way of work from me for years, until recently. I just found out that IT Security has changed the security settings on the user's PCs to prevent them from saving files to their C drives, and they didn't bother to tell me or anyone else.

Here is the piece of code that is currently being used:

Code:
OpenTextFile("c:\ge.TXT", 8, True)

My question is two part. 1)How would I get this to go to the My Documents path on the user's PC, and 2)Would the answer to part 1 be affected by whether the user was using XP or Windows 7?

TIA

MMund
 
What is OpenTextFile ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you use the scripting library then have a look at SpecialFolders("MyDocuments")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OpenTextFile is a VBA function that opens or creates a text file. In this case, the "c:\ge.txt" is the file path and name, the 8 means make it writeable, and the True means create it if it doesn't exist.
 
>OpenTextFile is a VBA function

To be pedantic, it is not a VBA function. It is a method of the FileSystemObject class library
 
Some companies choose to prevent users from writing to C:\ drive, but set up a server where users can keep their ‘work related’ stuff. Sometimes they even map that server to be, for example, a X:\ drive on every machine. Check with your IT if you have a place on the server where any user can write into.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top