Thread: Text Files
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
urkec urkec is offline
external usenet poster
 
Posts: 131
Default Text Files

Sub LoadTXTToCell(filePath As String)

ForReading = 1

Set fso = CreateObject _
("Scripting.FileSystemObject")

If fso.FileExists(filePath) Then
Set txtFile = fso.OpenTextFile _
(filePath, ForReading)
Else
Exit Sub
End If

ActiveWorkbook.Sheets(1).Cells(1, 1) = _
txtFile.ReadLine
'or
'txtFile.ReadAll

txtFile.Close

End Sub

--
urkec


"AJM1949" wrote:

Thanks very much. That seems to work fine.
I also need some help to read these stored values back into a cell.
Can you help with this
--
AJM1949


"urkec" wrote:

(1)


Sub SaveCellToTXT()

Set fso = CreateObject _
("Scripting.FileSystemObject")

Set txtFile = fso.CreateTextFile _
("C:\test1.txt", True)

txtFile.WriteLine _
ActiveWorkbook.Sheets(1).Cells(1, 1)

txtFile.Close

End Sub

(2)

Sub SaveTextBoxToTXT()

Set fso = CreateObject _
("Scripting.FileSystemObject")

Set txtFile = fso.CreateTextFile _
("C:\test2.txt", True)

'UserForm1.TextBox1.Value = "test"

txtFile.WriteLine _
UserForm1.TextBox1.Value

txtFile.Close


End Sub

Hope that helps.

--
urkec


"AJM1949" wrote:

How can I store a value in a text file from (1) a cell reference (2) a text
box on a form?

Thanks in advance for your help
--
AJM1949