Attachment 588544
all i wanted was to separate out the data into txt files of 50 columns (with no speech marks)...the data is more complicated then one attached...
I got it working with a little modification but i cant seem to get the txt files.....Any ideas?
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" _
(ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH As Long = 260
Function TempPath() As String
TempPath = String$(MAX_PATH, Chr$(0))
GetTempPath MAX_PATH, TempPath
TempPath = Replace(TempPath, Chr$(0), "")
End Function
Sub Findexpand()
Dim rFound As Range, FirstFound As Range
Dim FCell As String
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet1")
Dim k As Long
Dim tmpFile As String
Dim MyData As String, strData() As String
Dim entireline As String
Dim filesize As Integer
Dim Test As Boolean
Dim numRows As Long, numColumns As Long '''''' NEED VALUES
Dim i As Long
Dim FlName As String
Dim Sequence As Long
On Error Resume Next
Set rFound = Cells.Find(What:="*", _
After:=Cells(Rows.Count, Columns.Count), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If rFound Is Nothing Then
MsgBox "NotHing found"
Else
Set FirstFound = rFound
Do
ThisWorkbook.Sheets("Sheet1").Activate
FCell = rFound.Address(RowAbsolute:=False, ColumnAbsolute:=False, External:=False)
k = sh.Range(FCell, sh.Range(FCell).End(xlDown).End(xlDown).End(xlUp)).Rows.Count
ActiveSheet.Range(FCell).Select
Selection.Resize(numRows + k, numColumns + 50).Select
Selection.Cut
ActiveWorkbook.Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Paste
'~~> change this to orginal file location
Sequence = Sequence + 1
FlName = "C:\Users\Max\Desktop" & Sequence & ".txt"
'~~> Create a Temp File
tmpFile = TempPath & Format(Now, "ddmmyyyyhhmmss") & ".txt"
ActiveWorkbook.SaveAs Filename:=tmpFile _
, FileFormat:=xlText, CreateBackup:=False
'~~> Read the entire file in 1 Go!
Open tmpFile For Binary As #1
MyData = Space$(LOF(1))
Get #1, , MyData
Close #1
strData() = Split(MyData, vbCrLf)
'~~> Get a free file handle
filesize = FreeFile()
'~~> Open your file
Open FlName For Output As #filesize
For i = LBound(strData) To UBound(strData)
entireline = Replace(strData(i), """", "")
'~~> Export Text
Print #filesize, entireline
Next i
Close #filesize
Application.DisplayAlerts = False
'Worksheets(Worksheets.Count).Activate
'ActiveSheet.Delete
'Application.DisplayAlerts = True
' Kill tmpFile
ThisWorkbook.Sheets("Sheet1").Activate
Set rFound = Cells.FindNext(After:=rFound)
Loop Until rFound Is Nothing 'Or rFound.Address = FirstFound
End If
MsgBox "Done"
End Sub
I need the txt files in the same directory as the excel file, but it only works for one text file if i use
FlName = "C:\Users\Max\Desktop\chunk1.txt"
when i use
FlName = "C:\Users\Max\Desktop\chunk" & Sequence & ".txt"
no txt files are created...
Bookmarks