Add data to a text file

  • Thread starter Thread starter P
  • Start date Start date
P

P

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.
 
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
 

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

Back
Top