Created
January 5, 2023 17:28
-
-
Save lotusorrose/5a9e3ce5b2dfb02fe961375e83efe86b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Dim maxChars As Long | |
Dim txt As String | |
Dim newtxt As String | |
Dim curcounter As Long | |
Public Sub main() | |
maxChars = 80 | |
txt = ActiveDocument.Content.Text | |
txt = Replace(txt, vbNewLine, " ") | |
txt = Replace(txt, vbLf, " ") | |
txt = Replace(txt, vbCr, " ") | |
txt = Replace(txt, vbTab, " ") | |
txt = Replace(txt, " ", " ") | |
newtxt = "" | |
curcounter = 1 | |
While curcounter < Len(txt) | |
If curcounter + maxChars < Len(txt) Then | |
newtxt = newtxt & vbCrLf & Mid(txt, curcounter, InStrRev(txt, " ", curcounter + maxChars) - curcounter) | |
Else | |
newtxt = newtxt & vbCrLf & Mid(txt, curcounter) | |
End If | |
curcounter = CLng(InStrRev(txt, " ", curcounter + maxChars)) | |
If curcounter = 0 Then | |
curcounter = Len(txt) | |
End If | |
Wend | |
ActiveDocument.Content.Text = newtxt | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment