CatWithaWhiteHat
New Member
- Joined
- Apr 10, 2020
- Messages
- 2
- Office Version
- 2010
- Platform
- Windows
I have been able to put together the below code.
It reads the cell contents into a text file.
But I cant work out how to generate the code necessary to read a text file back into an excel worksheet.
Any help in generating the necessary code is gratefully appreciated
It reads the cell contents into a text file.
But I cant work out how to generate the code necessary to read a text file back into an excel worksheet.
Any help in generating the necessary code is gratefully appreciated
VBA Code:
Sub test3()
Dim ifile1 As Integer
Dim irow As Integer
Dim iName As String
Dim icolour As String
Dim inum As String
'free file number
ifile1 = FreeFile
'location to write to
Open "D:\XXXX\Documents\XXXX Test Freefile3.txt" For Output As #ifile1
'line to start at
irow = 2
'read through the cells
Do
With Sheets("Sheet1")
iName = .Cells(irow, 1).Value
icolour = .Cells(irow, 2).Value
inum = .Cells(irow, 3).Value
End With
'action to do
Write #ifile1, iName, icolour, inum
'step each time to a new line
irow = irow + 1
'loop to do till there is no more data in the cells
Loop Until IsEmpty(Sheets("Sheet1").Cells(irow, 1).Value)
'close the open file
Close #ifile1
End Sub