Sub ExportSheetsToText_Fast()
Dim ws As Worksheet
Dim filePath As String
Dim r As Long, c As Long
Dim lastRow As Long, lastCol As Long
Dim lineText As String
Dim fnum As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each ws In ThisWorkbook.Worksheets
filePath = ThisWorkbook.Path & "\" & ws.Name & ".txt"
fnum = FreeFile
Open filePath For Output As #fnum
lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
For r = 1 To lastRow
lineText = ""
For c = 1 To lastCol
lineText = lineText & ws.Cells(r, c).Text
If c < lastCol Then lineText = lineText & vbTab
Next c
Print #fnum, lineText
Next r
Close #fnum
Next ws
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "Export completed!"
End Sub
0 Nhận xét