Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Load text file and write back

Hi,

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

Regards,

Sanja

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
load a CSV file and have it take all fields as text cj Excel Discussion (Misc queries) 5 March 29th 07 02:24 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
Can I load text file into Excel seting field delimter using cmd li Tim Excel Discussion (Misc queries) 0 April 19th 05 01:55 AM
how to write other language in text file from VBA Ravi Excel Programming 1 January 27th 04 03:21 AM
write a line from Excel to a text file julian_bro Excel Programming 1 September 30th 03 01:29 AM


All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"