• 0

Export Data From Excel To Text File By Batch

  • 0

Dear all,

could you show me plz how to create a batch file can
export data from excel to text file and save this text file in (C:\) drive

plz i need your help


1 Answer

  1. Hi,

    Here is a short macro that creates a text file from Excel data.

    Sub Export()
    Dim objFs As Object
    Dim objText As Object
    Dim strData As String
    Dim n As Integer
    Set objFs = CreateObject("Scripting.FileSystemObject")
    'create the text file with Path & text filename
    Set objText = objFs.CreateTextFile("C:\MyExcelData.txt", 1)
    'create a string from the data
    For n = 0 To 20
        strData = strData & ActiveSheet.Range("B2").Offset(n, 0).Text & vbCrLf
    Next n
    'write the string to the text file
    objText.WriteLine (strData)
    'close the text file
    'remove the file system object
    Set objFs = Nothing
    End Sub

    It includes a loop to collect data from cells in a column starting at cell B2, using an offset to move through a range.
    There are lots of ways to collect the data, so you can modify the data capture to suit your needs and still use the basic file system.

    Hope this helps.


    • 0