View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Add data to a text file

Here is some sample code previously posted by Patrick Malloy

Private Sub WriteLog()
' trap error in case network not available
On Error GoTo trap
Dim log As String ' for the text to send to the log file
Dim ff As Long ' for the link to the text file
ff = FreeFile ' get a free file chammel
' create the text for the log
log = Format(Date, "ddd dd-mmm-yyyy") & " BookX opened as "
If ThisWorkbook.ReadOnly Then
log = log & "Read Only."
Else
log = log & "Read Write."
End If
' open the file for append
'note: if the file doesn't exist then it will be created automatically
Open "X:\LogFolder\THISBOOK_LOG.TXT" For Append As ff
' send the text to the log file
Print #ff, log
' then close it
Close #ff

trap: Err.Clear


End Sub


--

Regards,

Tom Ogilvy



"P" wrote in message
...
Hello Experts,

I am interested to write contents of excel worksheet to a system file.

From MSDN i fould reference to filesystemobject in VBScript. But i am not
able to access "fileSystemObject" in Excel.

Any solution.

I would like to append to a log.txt to reflect the usage of the excel
Workseet and a a snapshot of performed taks.


--
Purnank