Copying data from excel to txt file with tab delimited
Hi ,
Basically I am writing one macro in Excel 2003 VBA which will copy data from Excel file to .txt file . I want to copy all data from Excel to txt file with a tab delimited . I trying to write the code as below please have a look .
Sub ListSheets()
Dim ws As Worksheet
Dim x As Integer
Dim colcnt As Integer
x = 1
Sheets("Sheet1").Range("A:A").Clear
For Each ws In Worksheets
Sheets("Sheet1").Cells(x, 1) = ws.Name
x = x + 2
Next ws
b = Format(Now(), "MMddyyyy")
For i = 0 To 3
i = i + 1
If Cells(i, 1) = "Sheet1" Then
GoTo end3
Else
Open "C:\AHHNuanceData.txt" For Output As #1
Application.Sheets(Cells(i, 1).Value).Activate
For j = 2 To 65536 // rows
j = j - 1
If Cells(j, 7) = "" Then
GoTo end2
Else
For k = 1 To 205 // columns
Print #1, Cells(j, k).Value & Chr(9)
Next k
End If
j = j + 1
Next j
end2:
Close #1
Application.Sheets("Sheet1").Activate
End If
Next i
end3:
End Sub
The code is working fine just one problem
suppose i have below columns in excel
First_ name Last_name City
--------------------------------
Deepika Vispute Pune
-------------------------------
Then in txt my code is printing
-----------------------
Deepika
Vispute
pune
--------------------------
but I want
----------------------------
Deepika Vispute Pune
-------------------------------
just like in excel .
I am ussing
Print #1
Which is printing each data in new line bydefault
I donât want that
can anyone help me to get the output in proper format as it is in excel
Please help me on this .
|