Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default 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?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DDE Logging Data Loss in Excel PSY_UK Excel Discussion (Misc queries) 0 December 1st 05 09:01 AM
Live DDE Data Logging MadManInABox Excel Discussion (Misc queries) 1 September 19th 05 09:40 AM
Logging Data Single Input ExcelDanHarris Excel Programming 1 July 9th 05 05:44 PM
Copy data from textfile, paste and transpose to sheet2 m4nd4li4 Excel Programming 1 March 14th 05 04:05 PM
Logging data from a web query Rob Excel Programming 1 July 31st 03 01:25 PM


All times are GMT +1. The time now is 08:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"