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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing at the end of the file

Status
Not open for further replies.

pghTech

Technical User
Jul 19, 2006
37
US
I am familar with some of the opentextfile properties, but the problem is that the either pertain to opening a file to "read" or "write", but properties that I need to use either are one or the other and I need both.

I need to open a file, find the last character, go to the next line and write two lines to the file. There is a way to find the last character in the file, but appears to only be usable when opening the file as "read", but I need to write. So do I have to collect that location into a variable, then use that variable to open the file again to write, and go to that position?
 
do a search for append to text file

thread329-558707


[thumbsup2] Wow, I'm having amnesia and deja vu at the same time.
I think I've forgotten this before.


 
If you're just appending to a text file:

const ForReading = 1
Set objFSO = CreateObject("Scipting.FileSystemObject")
strFile = "C:\temp.txt"
Set objFile = objFSO.OpenTextFile (strFile, ForReading)
strFile = objFile.ReadAll
strFile = strFile & AppendedText
objFile.Close
Set objFile = objFSO.CreateTextFile(strFile)
objFile.WriteLine strUsrs
objFile.Close

If you're appending to a Word document:
 
Why not simply open the file ForAppending (8) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Didn't know you could open for appending until MrMilson's post with the link to the other thread. Much easier than my code, so I gave you a star in that thread. I didn't see any point to repost to use ForAppending.
 
you have to do 2 operations:
one for reading to find the last character in the file
two for appending to write your lines to the end of the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top