Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using text files

I have a problems working with files in excel vba.
Can somebody please tell me a little about this problem.

I just want to read from txt fail char-by-char and make a string from
each line and then work with these strings. Is it possible?

Here I'm just trying to do something with files. But no luck :(

Private Sub with_files()
Open "C:\WINDOWS\Desktop\Projekt\minu" For Random Access Read Write
lock Write As #3 Len = Len(" ")
Put #3, , "M"
' Here it says that bad record lenght and error 59.
Get #3, , loetud
MsgBox loetud
Close #3
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using text files

If you run the 'character' example, you will see that the output might
not be very useful for your purpose (includes end of line character
13). The 'get lines' one will probably be best. You will, of course,
need to point to one of your own files.

'---------------------------------------------------
Sub GET_CHARACTERS()
Dim MyChar
ToRow = 1
Open "C:\test.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Get one character.
ActiveSheet.Cells(ToRow, 1).Value = MyChar
ToRow = ToRow + 1
Loop
Close #1 ' Close file.
End Sub

'-----------------------------------------------------
Sub GET_LINES_FROM_TEXTFILE()
Dim MyString As String
Dim ToRow As Long
'----------------------
ToRow = 1
Open "C:\test.txt" For Input As #1 ' Open file
Do While Not EOF(1) ' Check for end of file.
Line Input #1, MyString ' Read line of data.
ActiveSheet.Cells(ToRow, 1).Value = MyString
ToRow = ToRow + 1
Loop
Close #1 ' Close file.
End Sub
'------------------------------------------------------


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

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
Files saved as csv files are actually saved as text files? Queen_Of_Thebes[_2_] Excel Discussion (Misc queries) 2 May 19th 09 03:04 PM
Text Files KarenW Excel Discussion (Misc queries) 2 March 27th 09 11:19 AM
Excel (xls) files spontaneously converting to text files Be-jamin Excel Discussion (Misc queries) 0 November 18th 08 05:31 PM
Text Files Chris Excel Discussion (Misc queries) 1 June 13th 07 02:34 PM
how do i convert text files into CSV files? airpr23 Excel Discussion (Misc queries) 2 February 28th 07 12:56 AM


All times are GMT +1. The time now is 09:48 AM.

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

About Us

"It's about Microsoft Excel"