Text File

S

sparx

How can I make an Excel file create a text file ( only if the text file
is not already created ) and keep adding details into that text file (
what is written across say 1 row thats made up of date, time, etc etc )
so I can look back in the text file as a kind of history file. This
could be done every time the Excel file changes or say only when the
file has been opened so it keeps a log of file opening and saving times
etc??? - If this is possible, I could provide a more detailed
explanation of what I need - Thanks
 
B

Bryan Hessey

You would need to write some VB code to do that, or you could use the
Track Changes option in Excel.

Select Tools, Track Changes, and select your options.

Hope this helps

--
 
S

Steve Yandl

Here is a start.

Sub LogToTextFile()
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
Set report = fso.OpenTextFile("C:\Test\xlrprt.txt", ForAppending, True, 0)
report.WriteLine Sheets(1).Cells(1, 1).Value
report.Close
Set report = Nothing
Set fso = Nothing
End Sub


The sub above assumes that the folder "C:\Test" exists. It will create the
text file xlrprt.txt in that folder if it doesn't already exist. It will
add a line to the end of the text file that in this example is the value
found in Cell A1 on Sheet1.

It sounds like you want this sub to be triggered by an event rather than the
way I show it. I'd probably go with the window activate event or something
similar but it kind of depends on the details of what you want to record in
the text file.

Steve
 
S

sparx

Thanks for your reply - your VBA code works a treat - only thing is for
it to copy more than only one cell, lets say approx A1:T1 ( 20 columns
) but all on one row. I think I might be able to run your vba in the
workbook section so it copies a log of file use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top