![]() |
Logging data using the same textfile over and over again
Hey all.
I am working on a log-like mechanism in VBA. I programmed the following sub: Sub CreateLog() Datum = Date Tijd = Time Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("H:\test " + Cstr(Datum) + ".txt", True) a.WriteLine("The process begun @ " + Cstr(Tijd) + " on " + Cstr(Datum)) a.close End Sub But this overwrites the textfile over and over again. I would like it to open the existing textfile, and add a new line (the same line as above) on top of the other line(s) The result would be a summary of lines in one textfile. Everytime this macro is activated i would like to be an line added. is this possible? if yes, please could anyone help me? |
Logging data using the same textfile over and over again
Hello Silencer,
Yust need to append the text to the existing text file. Const ForAppending = 8 Set objTextFile = fs.OpenTextFile (strDirectory & strFile, ForAppending, True) objTextFile.WriteLine "text" Best Regards, Agnieszka |
Logging data using the same textfile over and over again
You might be able to adapt the following, it creates a login record in a
text file (appends each time the workbook is opened). Does not use FSO scripting either! Private Sub Workbook_Open() Open ThisWorkbook.Path & "\TrackUsage.log" For Append As #1 Print #1, Application.UserName, Now, "Opened" Close #1 End Sub -- Cheers Nigel "Silencer116" wrote in message oups.com... Hey all. I am working on a log-like mechanism in VBA. I programmed the following sub: Sub CreateLog() Datum = Date Tijd = Time Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("H:\test " + Cstr(Datum) + ".txt", True) a.WriteLine("The process begun @ " + Cstr(Tijd) + " on " + Cstr(Datum)) a.close End Sub But this overwrites the textfile over and over again. I would like it to open the existing textfile, and add a new line (the same line as above) on top of the other line(s) The result would be a summary of lines in one textfile. Everytime this macro is activated i would like to be an line added. is this possible? if yes, please could anyone help me? |
Logging data using the same textfile over and over again
Hey Agnieszka and Nigel
Thanks for your quick responds! i'll try it right away! |
All times are GMT +1. The time now is 02:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com