Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7551545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:31:27+00:00 2026-05-30T10:31:27+00:00

Is it possible to read and write csv files using FileSystemObject in VBA?

  • 0

Is it possible to read and write csv files using FileSystemObject in VBA?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:31:29+00:00Added an answer on May 30, 2026 at 10:31 am

    It certainly is.

    Basic syntax such as

        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) 
    

    will create/open a CSV with FSO.

    The CSV can then be modified by writing to it

    While this is an Excel example you can use the same technique to write records from Outlook, Access, Word etc

    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 > 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) > 0, """" & X(1, lCol) & """", X(1, lCol))
                        For lRow = 2 To UBound(X, 1)
                            'concatenate long string & (short string with short string)
                            strTmp = strTmp & (strDelim & IIf(InStr(X(lRow, lCol), strDelim) > 0, """" & X(lRow, lCol) & """", X(lRow, lCol)))
                        Next lRow
                        'write each line to CSV
                        objTF.writeline strTmp
                    Next lCol
                Else
                    objTF.writeline IIf(InStr(ws.UsedRange.Value, strDelim) > 0, """" & ws.UsedRange.Value & """", ws.UsedRange.Value)
                End If
            End If
        Next ws
    
        objTF.Close
        Set objFSO = Nothing
        MsgBox "Done!", vbOKOnly
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to read and write Word (2003 and 2007) files in Python
Is it possible to read and write Word (2003 and 2007) files in PHP
how can I write and read files in JavaScript? Is it possible?
Possible Duplicate: read/write to Windows Registry using Java I want to read the registry
Is it possible to handle (read and write) binary data to SQL Server using
I want to know is it possible to read/write google spreadsheets using GET/POST methods
Is it possible to read binary MATLAB .mat files in Python? I've seen that
Possible Duplicate: Invalid read/write sometimes creates segmentation fault and sometimes does not I have
I need to write a C program that will allow me to read/write files
I wondered if it's possible to write some data to CSV file in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.