Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It certainly is.</p> <p>Basic syntax such as</p> <pre><code> Set objFSO = CreateObject("scripting.filesystemobject") 'create a csv file Set objTF = objFSO.createtextfile("C:\test\myfile.csv", True, False) 'open an existing csv file with writing ability Set objTF = objFSO.OpenTextFile("C:\test\myfile.csv", 8) </code></pre> <p>will create/open a <code>CSV</code> with <code>FSO</code>.</p> <p>The <code>CSV</code> can then be modified by writing to it</p> <p>While this is an Excel example you can use the same technique to write records from Outlook, Access, Word etc</p> <pre><code>Const sFilePath = "C:\test\myfile.csv" Const strDelim = "," Sub CreateCSV_FSO() Dim objFSO Dim objTF Dim ws As Worksheet Dim lRow As Long Dim lCol As Long Dim strTmp As String Dim lFnum As Long Set objFSO = CreateObject("scripting.filesystemobject") Set objTF = objFSO.createtextfile(sFilePath, True, False) For Each ws In ActiveWorkbook.Worksheets 'test that sheet has been used Set rng1 = ws.UsedRange If Not rng1 Is Nothing Then 'only multi-cell ranges can be written to a 2D array If rng1.Cells.Count &gt; 1 Then X = ws.UsedRange.Value2 'The code TRANSPOSES COLUMNS AND ROWS by writing strings column by column For lCol = 1 To UBound(X, 2) 'write initial value outside the loop strTmp = IIf(InStr(X(1, lCol), strDelim) &gt; 0, """" &amp; X(1, lCol) &amp; """", X(1, lCol)) For lRow = 2 To UBound(X, 1) 'concatenate long string &amp; (short string with short string) strTmp = strTmp &amp; (strDelim &amp; IIf(InStr(X(lRow, lCol), strDelim) &gt; 0, """" &amp; X(lRow, lCol) &amp; """", X(lRow, lCol))) Next lRow 'write each line to CSV objTF.writeline strTmp Next lCol Else objTF.writeline IIf(InStr(ws.UsedRange.Value, strDelim) &gt; 0, """" &amp; ws.UsedRange.Value &amp; """", ws.UsedRange.Value) End If End If Next ws objTF.Close Set objFSO = Nothing MsgBox "Done!", vbOKOnly End Sub </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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