View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Load text file and write back

It's possible, but you don't need to do that much work.

Option Explicit
Sub testme01()

Dim myNumber As Long
Dim myLine As String
Dim myFileName As String
Dim FileNum As Long

myFileName = "C:\my documents\excel\text.txt"
FileNum = FreeFile

'read previous number:
If Dir(myFileName) = "" Then 'not found
MsgBox "File is missing!"
Exit Sub
Else
Close FileNum
Open myFileName For Input As FileNum
Do While Not EOF(FileNum)
Line Input #FileNum, myLine
myNumber = Val(myLine)
Loop
Close FileNum
End If

myNumber = myNumber + 1

Open myFileName For Output As FileNum
Print #FileNum, myNumber
Close FileNum

End Sub



"sanjay <" wrote:

Hi,

Is it possible for me to read a text file (just contains a number) and
write the number to a cell and then increment that number and save that
back into the text file?

Regards,

Sanjay

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson