| Member with 4,530 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Advanced | |
Here is code I wrote to export your Excel to text with quotes and delimited by commas. Check it out & let me know how it works for you. You only need to change the line Set fsoText = fso.CreateTextFile("C:\Test.txt", True) to reflect the true path of where you want the text file created. The code assumes that the first row of data will contain title headers that do not need to be written to the text file. If you need to include row 1 in the export just change the row number (2) to start in my code to whatever row you want to start from ( For i = 2 )
Could you also tell me what does Column "I" (PR) represent? Currently when this value is written to the text file it is being written as a numeric value. I need to know what format to use when transferring to text (date, time, etc.) Code: Public Sub ExportText()
Dim fso
Dim aArray As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoText = fso.CreateTextFile("C:\Test.txt", True)
vCol = Left(Columns(Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column).Address(0, 0), 2 + (Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column < 27))
For i = 2 To Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ReDim aArray(1 To 1, 1 To Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column)
aArray = Range("A" & i & ":" & vCol & i).Value
For x = 1 To Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
If vString = "" Then
vString = Chr(34) & aArray(1, x) & Chr(34)
Else
vString = vString & " , " & Chr(34) & aArray(1, x) & Chr(34)
End If
Next x
fsoText.WriteLine (vString)
vString = ""
Next i
MsgBox ("TEXT EXPORT COMPLETE")
fsoText.Close
Set fso = nothing
set aArray = nothing
End Sub Regards,
Rollin
Last edited by Rollin_Again; 28-Apr-2007 at 10:25 AM..
|