This should be a piece of cake for you guys...
Sub Text_Export()
Dim strDeskTop As String
Dim objWSH As Object
Dim rngData As Range
Dim lngRow As Long
Dim lngCol As Long
Dim strFileName As String
Dim strBuffer As String
Dim intUnit As Integer
Set objWSH = CreateObject("WScript.Shell")
strDeskTop = objWSH.SpecialFolders("Desktop") & "\Thesis\Route_Database_Numbers\"
Set rngData = ActiveSheet.Range("A1").CurrentRegion
For lngCol = 2 To rngData.Columns.Count
strFileName = strDeskTop & rngData.Cells(lngCol, 1).Text & ".txt"
intUnit = FreeFile
Open strFileName For Output As intUnit
strBuffer = ""
For lngRow = 2 To rngData.Rows.Count
strBuffer = strBuffer & rngData.Cells(lngCol, lngRow).Text
Next
Print #intUnit, Left(strBuffer, Len(strBuffer))
Close intUnit
Next
Set objWHS = Nothing
End Sub
The code above will produce text files from a square matrix with the first column as the text file name,
and the each row from the second row as the content of the corresponding title (from column 1).. e.g:
1 2 3
1 a t y
2 d v j
3 e u k
From that matrix we'll get :
1.txt, contains aty
2.txt, contains dvy
3.txt, contains euk
Now i want to modificate the code so that it would create a single text file, with all the matrix cells as the content..
(the title doesn't matter, as it's only one file) e.g:
one.txt , contains atydvyeuk
I've been switching the "for.. next" in the code but i can't seem to get the right result
thanks in advance.
Bookmarks