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!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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