Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are lucky, your data look like this:</p> <p><img src="https://i.stack.imgur.com/ek1D0.jpg" alt="enter image description here"></p> <p>and you don't need fancy formatting in the .CSVs, you may get away with using .GetString(, cnStep, ...) on the recordset and some RegExps to fix the quotes, as examplified by this proof of concept script:</p> <pre><code>' want-to-automate-excel-work-of-copying-records-upto-10000-each-and-save-into-csv Option Explicit Const adClipString = 2 Const cnStep = 3 Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" ) WScript.Quit demoMain() Function demoMain() demoMain = 0 ' assume success Dim reClean : Set reClean = New RegExp reClean.Global = True reClean.Multiline = True reClean.Pattern = """(\d+)$" Dim reQuote : Set reQuote = New RegExp reQuote.Global = True reQuote.Multiline = True reQuote.Pattern = "^(.)" Dim sDDir : sDDir = "..\Data\SplitToCsv" Dim sXFSpec : sXFSpec = goFS.BuildPath(sDDir, "SplitToCsv.xls") Dim oXDb : Set oXDb = CreateObject("ADODB.Connection") ' based on: !! http://www.connectionstrings.com/excel oXDb.open Join(Array( _ "Provider=Microsoft.Jet.OLEDB.4.0" _ , "Data Source=" &amp; sXFSpec _ , "Extended Properties=""" _ &amp; Join(Array( _ "Excel 8.0" _ , "HDR=Yes" _ , "IMEX=1" _ ), ";" ) _ &amp; """" _ ), ";") Dim oRs : Set oRs = oXDb.Execute("SELECT * FROM [Everybody]") Dim sFs : sFs = getRsFNames(oRs) Dim nR : nR = 1 Do Until oRs.EOF Dim s : s = reQuote.Replace( _ reClean.Replace( _ oRs.GetString(adClipString, cnStep, """,""", vbCrLf) _ , "$1" _ ) _ , """$1" _ ) Dim f : f = goFS.BuildPath(sDDir, "R" &amp; nR &amp; "ff.csv") WScript.Echo f WScript.Echo s goFS.CreateTextFile(f, True).Write sFs &amp; vbCrLf &amp; s nR = nR + cnStep Loop oXDb.Close WScript.Echo goFS.OpenTextFile(f).ReadAll() End Function ' demoMain Function getRsFNames(oRs) ReDim a(oRs.Fields.Count - 1) Dim f For f = 0 To UBound(a) a(f) = """" &amp; oRs.Fields(f).Name &amp; """" Next getRsFNames = Join(a, ",") End Function ' getRsFNames </code></pre> <p>output:</p> <pre><code>cscript 10780869.vbs ..\Data\SplitToCsv\R1ff.csv "EM1","FN1",1 "EM2","FN2",2 "EM3","FN3",3 ..\Data\SplitToCsv\R4ff.csv "EM4","FN4",4 "EM5","FN5",5 "EM6","FN6",6 ..\Data\SplitToCsv\R7ff.csv "EM7","FN7",7 "EmailID","FirstName","Checksum" "EM7","FN7",7 </code></pre> <p>I tried to make it easy for you to tinker with the connection string; depending on your installation, you may have to change the version number and/or property names.</p> <p>You may notice the "OpenOffice" in the picture - that's one advantage of this approach: it works even on computers without Excel.</p> <p><strong>P.S.:</strong> I wrote this answer, when the question was still tagged vbscript.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload