Option Explicit
Sub CreateFixedWidthFile(strFile As String, ws As Worksheet, s() As Integer)
Dim i As Long, j As Long
Dim strLine As String, strCell As String
Dim fNum As Long
fNum = FreeFile
Open strFile For Output As fNum
For i = 1 To ws.Range("a65536").End(xlUp).Row
strLine = ""
For j = 0 To UBound(s)
strCell = Left$(ws.Cells(i, j + 1).Value, s(j))
strLine = strLine & strCell & String$(s(j) - Len(strCell), Chr$(32))
Next j
Print #fNum, strLine
Next i
Close #fNum
End Sub
Sub CreateFile()
Dim sPath As String
sPath = Application.GetSaveAsFilename("", "Text Files,*.txt")
If LCase$(sPath) = "false" Then Exit Sub
Dim s(6) As Integer
s(0) = 21
s(1) = 9
s(2) = 15
s(3) = 11
s(4) = 12
s(5) = 10
s(6) = 186
CreateFixedWidthFile sPath, ActiveSheet, s
End Sub
|