Limit Characters Per Line When Outputting to Excel to a Text File (Using VBA)

ronnietrahanjr

New Member
Joined
Jun 30, 2016
Messages
1
Greetings,

I have used the following two codes in an attempt to output excel to a text file:

1.
Sub Output()


Dim myFileName As String
myFileName = InputBox("Name Your Output File")
Range("B126").Value = myFileName

If myFileName = "" Or Range("B126") = "" Then
Exit Sub
End If

Open myFileName For Output As #1
Write #1, " " & vbNewLine & _
Range("ac3") & Range("ad3") & Range("ae3") & vbNewLine & _
Range("ac5") & Range("ad5") & Range("ae5") & vbNewLine & _
""
Close #1
End Sub

2.
Sub Output2()

Dim ws As Worksheet

Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Worksheets

Sheets(ws.Name).Select
Sheets(ws.Name).Copy
ActiveWorkbook.SaveAs Filename:=ws.Name & ".doc", _
FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close
ThisWorkbook.Activate
Next

End Sub

Each code will work. However, I cannot figure out how to limit each line to 60 characters; text wrap without cutting words in half; and then tab over so that each subsequent line falls in line as follows:

(1) XXXXXXXXXXXX(60 Characters)
XXXXXXXXXXXX
(2) YYYYYYYYYYYYYYY(60 Characters)
YYYYYYYYYYYYY

Can someone assist?

Thank you!
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Watch MrExcel Video

Forum statistics

Threads
1,108,732
Messages
5,524,516
Members
409,583
Latest member
gkarthick

This Week's Hot Topics

Top