|
rjackman1959
Yak Posting Veteran
60 Posts |
Posted - 2009-01-14 : 14:50:07
|
I am trying to save SQL results from a spread sheet to a comma delimitated file, but I don’t want the first line to have the quotes in front or at the end or be delimitated. I found this code that works great except it does not include the first row. And again I don’t want the first row to have the quotes or be coma delimitated. Can anyone help please?Here is the spread sheet fileISA*ZZ*TS810 *00* *ZZ*TEST *ZZ*TEST *000000*0000*U*00400*000000000*0*P*~1 BB AA BB AA BB AA BB AA BB AA BB2 BB AA BB AA BB AA BB AA BB AA BB3 BB AA BB AA BB AA BB AA BB AA BB4 BB AA BB AA BB AA BB AA BB AA BB5 BB AA BB AA BB AA BB AA BB AA BBHere is what I’m getting in the text file (Perfect except no header record)"1" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB""2" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB""3" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB""4" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB""5" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB" , "AA" , "BB"Here is the codePublic Sub ExportToText()Dim fsoDim aArray As VariantSet fso = CreateObject("Scripting.FileSystemObject")Set fsoText = fso.CreateTextFile("C:\MyFile.dat", 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).RowReDim aArray(1 To 1, 1 To Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _SearchDirection:=xlPrevious).Column)aArray = Range("A" & i & ":" & vCol & i).ValueFor x = 1 To Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _SearchDirection:=xlPrevious).ColumnIf vString = "" ThenvString = Chr(34) & aArray(1, x) & Chr(34)ElsevString = vString & " , " & Chr(34) & aArray(1, x) & Chr(34)End IfNext xfsoText.WriteLine (vString)vString = ""Next iMsgBox ("TEXT EXPORT COMPLETE")fsoText.CloseSet fso = NothingSet aArray = NothingEnd Sub |
|