Need to Save Multiple Excel to text tab delimited File

venugosr

New Member
Joined
Jul 9, 2014
Messages
46
Hi,

Please be informed that, daily i'll get minimum 20 to 30 excel workbook.
Each workbook, i need to open and save as Text(Tab Delimited) Only the first sheet. Its consuming more time.
So, if it is 30 files, then I need to do the same.

Could someone help to automate this?

Kindly let me know if you need any details.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I have the below code, but it will save all the sheets in the workbook, which i dont want.
I want the first sheet only to save, but for all the excel files in the folder.

Code:
Sub SaveSheets()
Dim ws As Worksheet
Dim book As Workbook
Dim count As Integer
For Each ws In ThisWorkbook.Worksheets
  Set book = Workbooks.Add
  count = book.Worksheets.count
  ws.Copy book.Worksheets(1)
  
  Application.DisplayAlerts = False
  book.Worksheets(1).SaveAs "G:\Sri\" & ws.Name & ".txt", xlTextWindows
  Application.DisplayAlerts = True
  book.Close False
  Set book = Nothing
Next
MsgBox "Files successfully created."
End Sub
 
Upvote 0
You need a Dir function loop. Try this, changing the folder path containing the workbooks where indicated.

Code:
Public Sub Save_Workbooks_As_Tabbed()

    Dim folderPath As String
    Dim fileName As String
    Dim p As Long
    
    folderPath = "C:\path\to\folder\"  'CHANGE THIS STRING
    
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
    
    Application.ScreenUpdating = False
    
    fileName = Dir(folderPath & "*.xls*")
    Do While fileName <> vbNullString
        Workbooks.Open folderPath & fileName
        p = InStrRev(fileName, ".") - 1
        ActiveWorkbook.SaveAs fileName:=folderPath & Left(fileName, p) & ".txt", FileFormat:=xlText, CreateBackup:=False
        ActiveWorkbook.Close False
        fileName = Dir
    Loop

    Application.ScreenUpdating = True
    
    MsgBox "Done"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,324
Messages
6,124,249
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top