Text File Spliting

Hi,
i am trying to split text file like paragraph by paragraph using FSO Method,But I am failed ,pls suggest me a good way to do that…

hi there, can u show a piece of ur text? until then maybe this code can help you.

Sub Foo()   
    Const ForReading = 1
    Dim arr
    Dim i
    Dim file
    Dim fso

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set file = fso.OpenTextFile("c:\temp\test.txt", ForReading)
    content = file.ReadAll
    
    arr = Split(content, vbTab)
    
    For i = 1 To UBound(arr)
        MsgBox i & ": " & arr( i )
    Next
End Sub

	Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor 

incididunt ut labore et dolore magna aliqua. 
	Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex 

ea commodo consequat.
	Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat 

nulla pariatur.
	Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt 

mollit anim id est laborum.

Hi @selva!

You can use ‘Chr(10)’ as delimiter in the Split method. For example:

 	Dim fso, f, a
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.OpenTextFile("filename.txt", 1)
	
	a = Split(f.ReadAll, Chr(10))
	for i=0 to UBound(a,1)
		MsgBox a(i)
	next

thank you very much…sorry for late updation

1 Like